Spaces:
Runtime error
Runtime error
fastapi test
Browse files- app.py +29 -8
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,15 +1,36 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
text = st.text_area('enter some text!')
|
| 5 |
-
|
| 6 |
classifier = pipeline("text-classification", model="hun3359/klue-bert-base-sentiment")
|
| 7 |
-
preds = classifier(text, top_k=None)
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
|
|
|
| 5 |
classifier = pipeline("text-classification", model="hun3359/klue-bert-base-sentiment")
|
|
|
|
| 6 |
|
| 7 |
+
# text = st.text_area('enter some text!')
|
| 8 |
+
|
| 9 |
+
# classifier = pipeline("text-classification", model="hun3359/klue-bert-base-sentiment")
|
| 10 |
+
# preds = classifier(text, top_k=None)
|
| 11 |
+
|
| 12 |
+
# sorted_preds = sorted(preds, key=lambda x: x['score'], reverse=True)
|
| 13 |
+
|
| 14 |
+
# for item in sorted_preds:
|
| 15 |
+
# item['score'] = round(item['score'], 5)
|
| 16 |
+
|
| 17 |
+
# if text:
|
| 18 |
+
# st.json(sorted_preds)
|
| 19 |
+
|
| 20 |
+
app = FastAPI()
|
| 21 |
+
|
| 22 |
+
@app.get("/")
|
| 23 |
+
async def root():
|
| 24 |
+
return {"messsage" : "Successfully Initiated"}
|
| 25 |
|
| 26 |
+
# 유저로부터 text를 받아서 감정 분석 결과를 반환해주는 API
|
| 27 |
+
@app.get("/sentiment/")
|
| 28 |
+
async def sentiment(text: str = None):
|
| 29 |
+
preds = classifier(text, top_k=None)
|
| 30 |
|
| 31 |
+
sorted_preds = sorted(preds, key=lambda x: x['score'], reverse=True)
|
| 32 |
+
|
| 33 |
+
for item in sorted_preds:
|
| 34 |
+
item['score'] = round(item['score'], 5)
|
| 35 |
+
|
| 36 |
+
return sorted_preds
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
torch
|
| 2 |
-
transformers
|
|
|
|
|
|
| 1 |
torch
|
| 2 |
+
transformers
|
| 3 |
+
fastapi
|