Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
class SentimentRequest(BaseModel):
|
| 11 |
text: str
|
|
|
|
| 1 |
+
import os
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# Set custom cache directory to avoid permission issues
|
| 7 |
+
os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
|
| 8 |
+
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
# Explicitly specify a model (avoid default selection)
|
| 12 |
+
MODEL_NAME = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 13 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model=MODEL_NAME)
|
| 14 |
|
| 15 |
class SentimentRequest(BaseModel):
|
| 16 |
text: str
|