-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_deploy.py
47 lines (41 loc) · 1.92 KB
/
run_deploy.py
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
38
39
40
41
42
43
44
45
46
47
"""
use streamlit to deploy them
"""
import pandas as pd
import streamlit as st
from typing import Tuple
from cleanrnns.fetchers import fetch_pipeline_for_classification
from cleanrnns.pipelines import PipelineForClassification
@st.cache(allow_output_mutation=True)
def cache_pipelines() -> Tuple[PipelineForClassification,
PipelineForClassification,
PipelineForClassification]:
rnn = fetch_pipeline_for_classification("rnn_for_classification")
lstm = fetch_pipeline_for_classification("lstm_for_classification")
bilstm = fetch_pipeline_for_classification("bilstm_for_classification")
return rnn, lstm, bilstm
def main():
# fetch a pre-trained model
rnn, lstm, bilstm = cache_pipelines()
st.title("The Clean Rnns - 긍 / 부정 감성분석")
text = st.text_input("문장을 입력하세요", value="제목은 시선을 끌지만 줄거리가 애매모호하다")
if st.button(label="분석하기"):
with st.spinner("로딩중..."):
# prediction with RNN
table = list()
pred, probs = rnn(text)
sentiment = "🟢(긍정)" if pred else "🔴(부정)"
probs = ["{:.4f}".format(prob) for prob in probs]
table.append(["RNN", sentiment, str(probs)])
pred, probs = lstm(text)
probs = ["{:.4f}".format(prob) for prob in probs]
sentiment = "🟢(긍정)" if pred else "🔴(부정)"
table.append(["LSTM", sentiment, str(probs)])
pred, probs = bilstm(text)
sentiment = "🟢(긍정)" if pred else "🔴(부정)"
probs = ["{:.4f}".format(prob) for prob in probs]
table.append(["BiLSTM", sentiment, str(probs)])
df = pd.DataFrame(table, columns=["모델", "예측", "확률분포 [부정, 긍정]"])
st.markdown(df.to_markdown(index=False))
if __name__ == '__main__':
main()