Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
from pydantic import BaseModel
|
3 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
-
import torch
|
5 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
6 |
-
|
7 |
-
# Initialize FastAPI app
|
8 |
-
app = FastAPI(title="Stress Detection API", version="1.0")
|
9 |
-
|
10 |
-
model = AutoModelForSequenceClassification.from_pretrained("SrivarshiniGanesan/finetuned-stress-model")
|
11 |
-
tokenizer = AutoTokenizer.from_pretrained("SrivarshiniGanesan/finetuned-stress-model")
|
12 |
-
|
13 |
-
|
14 |
-
# Request format
|
15 |
-
class TextInput(BaseModel):
|
16 |
-
text: str
|
17 |
-
|
18 |
-
@app.post("/predict")
|
19 |
-
def predict_stress(input_text: TextInput):
|
20 |
-
inputs = tokenizer(input_text.text, return_tensors="pt", padding=True, truncation=True)
|
21 |
-
with torch.no_grad():
|
22 |
-
logits = model(**inputs).logits
|
23 |
-
prediction = torch.argmax(logits, dim=-1).item()
|
24 |
-
|
25 |
-
return {"text": input_text.text, "stress_prediction": "Stress" if prediction == 1 else "No Stress"}
|
26 |
-
|
27 |
-
@app.get("/")
|
28 |
-
def home():
|
29 |
-
return {"message": "Welcome to the Stress Detection API!"}
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|