SrivarshiniGanesan commited on
Commit
e147874
·
verified ·
1 Parent(s): 5fc85b6

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -30
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
-