ak0601 commited on
Commit
3af8442
1 Parent(s): acb1aaf

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +26 -0
  2. requirements.txt +34 -0
main.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+
7
+ # Initialize the sentiment analysis pipeline
8
+ sentiment_pipeline = pipeline("sentiment-analysis")
9
+
10
+ class SentimentRequest(BaseModel):
11
+ text: str
12
+
13
+ class SentimentResponse(BaseModel):
14
+ label: str
15
+ score: float
16
+
17
+ @app.post("/sentiment", response_model=SentimentResponse)
18
+ async def analyze_sentiment(request: SentimentRequest):
19
+ text = request.text
20
+ results = sentiment_pipeline(text)
21
+ best_result = max(results, key=lambda x: x["score"])
22
+ return SentimentResponse(label=best_result["label"], score=best_result["score"])
23
+
24
+ if __name__ == "__main__":
25
+ import uvicorn
26
+ uvicorn.run(app, host="0.0.0.0", port=8000)
requirements.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.5.0
2
+ anyio==3.7.1
3
+ certifi==2023.7.22
4
+ charset-normalizer==3.2.0
5
+ click==8.1.7
6
+ colorama==0.4.6
7
+ fastapi==0.103.1
8
+ filelock==3.12.4
9
+ fsspec==2023.9.2
10
+ h11==0.14.0
11
+ huggingface-hub==0.17.3
12
+ idna==3.4
13
+ Jinja2==3.1.2
14
+ MarkupSafe==2.1.3
15
+ mpmath==1.3.0
16
+ networkx==3.1
17
+ numpy==1.26.0
18
+ packaging==23.1
19
+ pydantic==2.4.1
20
+ pydantic_core==2.10.1
21
+ PyYAML==6.0.1
22
+ regex==2023.8.8
23
+ requests==2.31.0
24
+ safetensors==0.3.3
25
+ sniffio==1.3.0
26
+ starlette==0.27.0
27
+ sympy==1.12
28
+ tokenizers==0.13.3
29
+ torch==2.0.1
30
+ tqdm==4.66.1
31
+ transformers==4.33.2
32
+ typing_extensions==4.8.0
33
+ urllib3==2.0.5
34
+ uvicorn==0.23.2