Spaces:
Runtime error
Runtime error
Abineshkumar77 commited on
Commit ·
abe3d88
1
Parent(s): 4171ec2
Add application file
Browse files- app.py +4 -4
- requirements.txt +5 -1
app.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Query
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
from scipy.special import softmax
|
| 4 |
from typing import Dict
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
# Load model and tokenizer
|
|
@@ -34,7 +38,3 @@ def analyze_sentiment(tweet: str) -> Dict[str, float]:
|
|
| 34 |
async def analyze_sentiment_endpoint(tweet: str = Query(..., description="The tweet to analyze")):
|
| 35 |
sentiment_scores = analyze_sentiment(tweet)
|
| 36 |
return {"sentiment": sentiment_scores}
|
| 37 |
-
|
| 38 |
-
# To run the application:
|
| 39 |
-
# 1. Save this code as `main.py`.
|
| 40 |
-
# 2. Run the command `uvicorn main:app --reload`.
|
|
|
|
| 1 |
+
import os
|
| 2 |
from fastapi import FastAPI, Query
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
from scipy.special import softmax
|
| 5 |
from typing import Dict
|
| 6 |
|
| 7 |
+
# Set TRANSFORMERS_CACHE to a writable directory
|
| 8 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/.cache"
|
| 9 |
+
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
# Load model and tokenizer
|
|
|
|
| 38 |
async def analyze_sentiment_endpoint(tweet: str = Query(..., description="The tweet to analyze")):
|
| 39 |
sentiment_scores = analyze_sentiment(tweet)
|
| 40 |
return {"sentiment": sentiment_scores}
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -3,4 +3,8 @@ uvicorn[standard]
|
|
| 3 |
transformers[standard]
|
| 4 |
torch[standard]
|
| 5 |
torchvision[standard]
|
| 6 |
-
torchaudio[standard]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
transformers[standard]
|
| 4 |
torch[standard]
|
| 5 |
torchvision[standard]
|
| 6 |
+
torchaudio[standard]
|
| 7 |
+
fastapi
|
| 8 |
+
uvicorn
|
| 9 |
+
transformers
|
| 10 |
+
scipy
|