File size: 1,004 Bytes
3de2036
d080b24
a3a8b1d
3de2036
f520c17
a3a8b1d
d080b24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3a8b1d
d080b24
 
 
 
0ae7b40
d080b24
 
 
 
 
 
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
36
37
import streamlit as st
from fastapi import FastAPI
from transformers import pipeline

classifier = pipeline("text-classification", model="hun3359/klue-bert-base-sentiment")

# text = st.text_area('enter some text!')

# classifier = pipeline("text-classification", model="hun3359/klue-bert-base-sentiment")
# preds = classifier(text, top_k=None)

# sorted_preds = sorted(preds, key=lambda x: x['score'], reverse=True)

# for item in sorted_preds:
#     item['score'] = round(item['score'], 5)

# if text:
#     st.json(sorted_preds)

app = FastAPI()

@app.get("/")
async def root():
    return {"messsage" : "Successfully Initiated"}

# 유저로부터 text를 받아서 감정 분석 결과를 반환해주는 API
@app.get("/sentiment/")
async def sentiment(text: str = None):
    preds = classifier(text, top_k=None)

    sorted_preds = sorted(preds, key=lambda x: x['score'], reverse=True)
    
    for item in sorted_preds:
        item['score'] = round(item['score'], 5)
    
    return sorted_preds