Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from typing import Dict
|
|
| 5 |
from PIL import Image
|
| 6 |
from io import BytesIO
|
| 7 |
import torch
|
| 8 |
-
from transformers import
|
| 9 |
from fastapi import FastAPI, File, UploadFile
|
| 10 |
from fastapi.responses import JSONResponse
|
| 11 |
import uvicorn
|
|
@@ -39,15 +39,21 @@ def load_florence_model():
|
|
| 39 |
try:
|
| 40 |
log_message("[*] Loading Florence-2 model and processor...")
|
| 41 |
|
| 42 |
-
# Load
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
# Load directly to CPU
|
| 46 |
-
model = base_model.to(DEVICE)
|
| 47 |
-
log_message("[ ] Model loaded on CPU")
|
| 48 |
-
|
| 49 |
model.eval()
|
| 50 |
-
processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 51 |
log_message("[ ] Florence-2 loaded and ready.")
|
| 52 |
except Exception as e:
|
| 53 |
log_message(f"[ERROR] Failed to load Florence-2 model: {e}")
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
from io import BytesIO
|
| 7 |
import torch
|
| 8 |
+
from transformers import AutoModelForVision2Seq, AutoProcessor
|
| 9 |
from fastapi import FastAPI, File, UploadFile
|
| 10 |
from fastapi.responses import JSONResponse
|
| 11 |
import uvicorn
|
|
|
|
| 39 |
try:
|
| 40 |
log_message("[*] Loading Florence-2 model and processor...")
|
| 41 |
|
| 42 |
+
# Load model and processor with specific configuration
|
| 43 |
+
processor = AutoProcessor.from_pretrained(
|
| 44 |
+
MODEL_ID,
|
| 45 |
+
trust_remote_code=True,
|
| 46 |
+
revision="9a515b7", # Pin to a specific version
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
model = AutoModelForVision2Seq.from_pretrained(
|
| 50 |
+
MODEL_ID,
|
| 51 |
+
trust_remote_code=True,
|
| 52 |
+
revision="9a515b7", # Pin to a specific version
|
| 53 |
+
torch_dtype=torch.float32,
|
| 54 |
+
).to(DEVICE)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
model.eval()
|
|
|
|
| 57 |
log_message("[ ] Florence-2 loaded and ready.")
|
| 58 |
except Exception as e:
|
| 59 |
log_message(f"[ERROR] Failed to load Florence-2 model: {e}")
|