-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (29 loc) · 918 Bytes
/
app.py
File metadata and controls
36 lines (29 loc) · 918 Bytes
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
import streamlit as st
import streamlit.components.v1 as stc
import requests
from requests.exceptions import Timeout
import base64
import json
st.title("MeCab Web App")
inputText = st.text_input("入力文:", value="今日は良い天気だ")
button = st.button("解析")
if button:
data = {
'text':inputText
}
isConnectedSuccess = False
try:
res = requests.post('http://0.0.0.0:8000/mecab', json.dumps(data), timeout=20.0)
if res.status_code == 200:
st.success(f"status_code:{res.status_code}")
isConnectedSuccess = True
else:
st.error(f"status_code:{res.status_code}")
except Timeout:
st.error(f"timeout")
except Exception as e:
st.error(f"error:{e}")
if isConnectedSuccess:
res_json = res.json()
res_result = res_json['result']
st.text(res_result)