Spaces:
Runtime error
Runtime error
macrdel
commited on
Commit
·
593cc35
1
Parent(s):
4a73553
update api.py
Browse files- app/api.py +10 -7
app/api.py
CHANGED
@@ -1,15 +1,18 @@
|
|
1 |
-
|
2 |
from app.src.src import pipeline_sentiment, pipeline_stats, pipeline_summarize
|
3 |
|
4 |
from fastapi import FastAPI
|
5 |
from pydantic import BaseModel
|
6 |
# from transformers import pipeline
|
7 |
-
import uvicorn
|
8 |
import pandas as pd
|
9 |
import os
|
10 |
|
11 |
# sentiment_model = pipeline(model=config.sentiment_model)
|
12 |
# sum_model = pipeline(model=config.sum_model, use_fast=True)
|
|
|
|
|
|
|
13 |
|
14 |
app = FastAPI()
|
15 |
|
@@ -22,9 +25,9 @@ def read_root():
|
|
22 |
|
23 |
@app.post('/comments')
|
24 |
def get_comments(url_video: YouTubeUrl):
|
25 |
-
data = pipeline_sentiment(url_video.url_video, config.API_KEY,
|
26 |
data.to_csv(f"{config.DATA_FILE}", index=False)
|
27 |
-
return {'message': 'Success'}
|
28 |
|
29 |
@app.get('/stats')
|
30 |
def get_stats_sent():
|
@@ -36,8 +39,8 @@ def get_stats_sent():
|
|
36 |
def get_summarize():
|
37 |
if f"{config.NAME_DATA}" in os.listdir(f"{config.PATH_DATA}"):
|
38 |
data = pd.read_csv(f"{config.DATA_FILE}")
|
39 |
-
return pipeline_summarize(data['text_comment'],
|
40 |
|
41 |
|
42 |
-
if __name__ == '__main__':
|
43 |
-
uvicorn.run(app, host='127.0.0.1', port=80)
|
|
|
1 |
+
from config import config, secrets
|
2 |
from app.src.src import pipeline_sentiment, pipeline_stats, pipeline_summarize
|
3 |
|
4 |
from fastapi import FastAPI
|
5 |
from pydantic import BaseModel
|
6 |
# from transformers import pipeline
|
7 |
+
# import uvicorn
|
8 |
import pandas as pd
|
9 |
import os
|
10 |
|
11 |
# sentiment_model = pipeline(model=config.sentiment_model)
|
12 |
# sum_model = pipeline(model=config.sum_model, use_fast=True)
|
13 |
+
headers = {"Authorization": f"Bearer {secrets.API_TOKEN}"}
|
14 |
+
SENT_API_URL = f"https://api-inference.huggingface.co/models/{config.sentiment_model}"
|
15 |
+
SUM_API_URL = f"https://api-inference.huggingface.co/models/{config.sum_model}"
|
16 |
|
17 |
app = FastAPI()
|
18 |
|
|
|
25 |
|
26 |
@app.post('/comments')
|
27 |
def get_comments(url_video: YouTubeUrl):
|
28 |
+
data = pipeline_sentiment(url_video.url_video, config.API_KEY, headers, SENT_API_URL)
|
29 |
data.to_csv(f"{config.DATA_FILE}", index=False)
|
30 |
+
return data # {'message': 'Success'}
|
31 |
|
32 |
@app.get('/stats')
|
33 |
def get_stats_sent():
|
|
|
39 |
def get_summarize():
|
40 |
if f"{config.NAME_DATA}" in os.listdir(f"{config.PATH_DATA}"):
|
41 |
data = pd.read_csv(f"{config.DATA_FILE}")
|
42 |
+
return pipeline_summarize(data['text_comment'], headers, SUM_API_URL)
|
43 |
|
44 |
|
45 |
+
#if __name__ == '__main__':
|
46 |
+
# uvicorn.run(app, host='127.0.0.1', port=80)
|