macrdel commited on
Commit
8843bcd
1 Parent(s): 3664152

import necessary libraries & add root hadler and get comments hadler

Browse files
Files changed (1) hide show
  1. app/api.py +25 -0
app/api.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import config
3
+ from pydantic import BaseModel
4
+ from transformers import pipeline
5
+ import uvicorn
6
+
7
+ sentiment_model = pipeline(config.sentiment_model)
8
+ app = FastAPI()
9
+
10
+ class YouTubeUrl(BaseModel):
11
+ url_video: str
12
+
13
+ @app.get('/')
14
+ def read_root():
15
+ return {'message': 'FastAPI+HuggingFace app sentiment + summarize YouTube comments'}
16
+
17
+ @app.post('/comments')
18
+ def get_comments(url_video: YouTubeUrl):
19
+ data = pipeline_sentiment(url_video.url_video, config.API_KEY, sentiment_model)
20
+ data.to_csv(f"{config.DATA_FILE}", index=False)
21
+ return {'message': 'Success'}
22
+
23
+
24
+ if __name__ == '__main__':
25
+ uvicorn.run(app, host='127.0.0.1', port=80)