Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
|
@@ -25,6 +25,12 @@ MAX_TOKENS = 4096
|
|
| 25 |
print(f"[Init] Loading model pipeline for the first time: {MODEL_NAME}...")
|
| 26 |
@spaces.GPU
|
| 27 |
def load_model():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
from unsloth import FastVisionModel
|
| 30 |
model, processor = FastVisionModel.from_pretrained(
|
|
@@ -34,18 +40,12 @@ def load_model():
|
|
| 34 |
use_gradient_checkpointing="unsloth",
|
| 35 |
token=os.environ["HF_API_KEY"],
|
| 36 |
)
|
| 37 |
-
return model, processor
|
| 38 |
except Exception as e:
|
| 39 |
print(f"[Error] Failed to load model: {e}")
|
| 40 |
raise Exception(f"❌ Model failed to load: {e}")
|
| 41 |
-
|
| 42 |
-
model, processor = load_model()
|
| 43 |
-
|
| 44 |
-
@spaces.GPU()
|
| 45 |
-
@torch.inference_mode()
|
| 46 |
-
def predict(image: Image.Image) -> str:
|
| 47 |
if image is None:
|
| 48 |
-
|
| 49 |
|
| 50 |
# Build prompt
|
| 51 |
messages = [
|
|
|
|
| 25 |
print(f"[Init] Loading model pipeline for the first time: {MODEL_NAME}...")
|
| 26 |
@spaces.GPU
|
| 27 |
def load_model():
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@spaces.GPU()
|
| 32 |
+
@torch.inference_mode()
|
| 33 |
+
def predict(image: Image.Image) -> str:
|
| 34 |
try:
|
| 35 |
from unsloth import FastVisionModel
|
| 36 |
model, processor = FastVisionModel.from_pretrained(
|
|
|
|
| 40 |
use_gradient_checkpointing="unsloth",
|
| 41 |
token=os.environ["HF_API_KEY"],
|
| 42 |
)
|
|
|
|
| 43 |
except Exception as e:
|
| 44 |
print(f"[Error] Failed to load model: {e}")
|
| 45 |
raise Exception(f"❌ Model failed to load: {e}")
|
| 46 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if image is None:
|
| 48 |
+
gr.warning("Please upload an image.")
|
| 49 |
|
| 50 |
# Build prompt
|
| 51 |
messages = [
|