File size: 1,899 Bytes
fba3401 | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <<<<<<< HEAD
# streamlit_app.py
import streamlit as st
import requests
st.title("IMDB 情感分析 Demo")
# 单条文本输入
text = st.text_area("输入文本", "This movie was amazing!")
if st.button("预测情感"):
response = requests.post(
"http://127.0.0.1:8000/predict",
json={"text": text}
)
result = response.json()
st.write(f"情感:{result['label']}")
st.write(f"置信度:{result['confidence']:.2f}")
# 批量文本输入
batch_texts = st.text_area("批量文本(每行一条)", "I loved it\nNot good")
if st.button("批量预测"):
texts_list = [line.strip() for line in batch_texts.split("\n") if line.strip()]
response = requests.post(
"http://127.0.0.1:8000/predict_batch",
json={"texts": texts_list}
)
results = response.json()
for r in results:
st.write(f"{r['text']} → {r['label']} ({r['confidence']:.2f})")
=======
# streamlit_app.py
import streamlit as st
import requests
st.title("IMDB 情感分析 Demo")
# 单条文本输入
text = st.text_area("输入文本", "This movie was amazing!")
if st.button("预测情感"):
response = requests.post(
"http://127.0.0.1:8000/predict",
json={"text": text}
)
result = response.json()
st.write(f"情感:{result['label']}")
st.write(f"置信度:{result['confidence']:.2f}")
# 批量文本输入
batch_texts = st.text_area("批量文本(每行一条)", "I loved it\nNot good")
if st.button("批量预测"):
texts_list = [line.strip() for line in batch_texts.split("\n") if line.strip()]
response = requests.post(
"http://127.0.0.1:8000/predict_batch",
json={"texts": texts_list}
)
results = response.json()
for r in results:
st.write(f"{r['text']} → {r['label']} ({r['confidence']:.2f})")
>>>>>>> 9ef5a78 (首次提交)
|