Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,9 @@ from pydantic import BaseModel
|
|
| 5 |
import os
|
| 6 |
import numpy as np # Explicit numpy import
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
# Fix numpy initialization
|
| 9 |
np.zeros(1) # Force numpy load before model
|
| 10 |
|
|
@@ -24,23 +27,22 @@ os.makedirs(os.environ["TRANSFORMERS_CACHE"], exist_ok=True)
|
|
| 24 |
def readiness_check():
|
| 25 |
return {"status": "ready"}
|
| 26 |
|
|
|
|
| 27 |
|
| 28 |
-
# Load model with error handling
|
| 29 |
try:
|
| 30 |
-
model =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
"text-classification",
|
| 32 |
-
model=
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
torch_dtype=torch.float32, # Avoid mixed precision
|
| 36 |
-
offline_mode=False, # Force fresh download
|
| 37 |
-
max_retries=3
|
| 38 |
)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
print("Model loaded successfully!")
|
| 42 |
except Exception as e:
|
| 43 |
-
print(f"
|
| 44 |
raise
|
| 45 |
|
| 46 |
class Request(BaseModel):
|
|
|
|
| 5 |
import os
|
| 6 |
import numpy as np # Explicit numpy import
|
| 7 |
|
| 8 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
# Fix numpy initialization
|
| 12 |
np.zeros(1) # Force numpy load before model
|
| 13 |
|
|
|
|
| 27 |
def readiness_check():
|
| 28 |
return {"status": "ready"}
|
| 29 |
|
| 30 |
+
model_name = "win2win/3-epochs-classifier-ver2"
|
| 31 |
|
|
|
|
| 32 |
try:
|
| 33 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 35 |
+
|
| 36 |
+
# Create pipeline with explicit classes
|
| 37 |
+
classifier = pipeline(
|
| 38 |
"text-classification",
|
| 39 |
+
model=model,
|
| 40 |
+
tokenizer=tokenizer,
|
| 41 |
+
device="cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
|
|
|
| 42 |
)
|
|
|
|
|
|
|
| 43 |
print("Model loaded successfully!")
|
| 44 |
except Exception as e:
|
| 45 |
+
print(f"Error loading model: {str(e)}")
|
| 46 |
raise
|
| 47 |
|
| 48 |
class Request(BaseModel):
|