iwin10s commited on
Commit
bc72390
·
verified ·
1 Parent(s): 8d40d6e

Upload api_app.py

Browse files
Files changed (1) hide show
  1. api_app.py +7 -12
api_app.py CHANGED
@@ -8,21 +8,16 @@ import os
8
 
9
  # --- Setup ---
10
  app = FastAPI()
11
- # Define the path where the model files will be located in the deployed environment
12
- MODEL_PATH = "." # In Hugging Face Spaces, files are often in the root directory
 
 
 
 
 
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")