Spaces:
Runtime error
Runtime error
Upload api_app.py
Browse files- api_app.py +7 -12
api_app.py
CHANGED
|
@@ -8,21 +8,16 @@ import os
|
|
| 8 |
|
| 9 |
# --- Setup ---
|
| 10 |
app = FastAPI()
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Load model and processor outside the endpoint for speed
|
| 15 |
-
try:
|
| 16 |
-
processor = AutoImageProcessor.from_pretrained(MODEL_PATH)
|
| 17 |
-
model = ViTForImageClassification.from_pretrained(MODEL_PATH)
|
| 18 |
-
except Exception as e:
|
| 19 |
-
# A fallback/debug print if loading fails during deployment
|
| 20 |
-
print(f"Error loading model or processor from {MODEL_PATH}: {e}")
|
| 21 |
-
# You might need to check file names or adjust MODEL_PATH if this fails
|
| 22 |
-
|
| 23 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 24 |
model.to(device)
|
| 25 |
-
model.eval()
|
| 26 |
|
| 27 |
# --- Prediction Endpoint ---
|
| 28 |
@app.post("/predict")
|
|
|
|
| 8 |
|
| 9 |
# --- Setup ---
|
| 10 |
app = FastAPI()
|
| 11 |
+
MODEL_PATH = "."
|
| 12 |
+
|
| 13 |
+
# --- CRITICAL CHANGE: REMOVE THE try/except BLOCK TEMPORARILY ---
|
| 14 |
+
# The deployment will crash, but the logs will show the exact reason.
|
| 15 |
+
|
| 16 |
+
processor = AutoImageProcessor.from_pretrained(MODEL_PATH)
|
| 17 |
+
model = ViTForImageClassification.from_pretrained(MODEL_PATH)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 20 |
model.to(device)
|
|
|
|
| 21 |
|
| 22 |
# --- Prediction Endpoint ---
|
| 23 |
@app.post("/predict")
|