File size: 979 Bytes
bd4ab21
2e8e71a
5da36ef
 
8843bcd
 
 
2e8e71a
 
8843bcd
bd4ab21
8843bcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e8e71a
 
 
 
 
 
8843bcd
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import config.config as config
from app.src.src import pipeline_sentiment, pipeline_stats

from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline
import uvicorn
import pandas as pd
import os

sentiment_model = pipeline(model=config.sentiment_model)
app = FastAPI()

class YouTubeUrl(BaseModel):
    url_video: str

@app.get('/')
def read_root():
    return {'message': 'FastAPI+HuggingFace app sentiment + summarize YouTube comments'}

@app.post('/comments')
def get_comments(url_video: YouTubeUrl):
    data = pipeline_sentiment(url_video.url_video, config.API_KEY, sentiment_model)
    data.to_csv(f"{config.DATA_FILE}", index=False)
    return {'message': 'Success'}

@app.get('/stats')
def get_stats_sent():
    if f"{config.NAME_DATA}" in os.listdir(f"{config.PATH_DATA}"):
        data = pd.read_csv(f"{config.DATA_FILE}")
        return pipeline_stats(data)


if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=80)