ShoaibSSM commited on
Commit
853fbe9
·
verified ·
1 Parent(s): 056838b

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -0
main.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ app = FastAPI()
5
+
6
+ # Initialize your model (this happens once when container starts)
7
+ classifier = pipeline("sentiment-analysis")
8
+
9
+ @app.get("/")
10
+ def read_root():
11
+ return {"message": "Hello from Hugging Face Spaces!"}
12
+
13
+ @app.post("/analyze")
14
+ def analyze_sentiment(text: str):
15
+ result = classifier(text)
16
+ return {"sentiment": result[0]["label"], "score": result[0]["score"]}