Spaces:
Running
Running
import streamlit as st | |
import requests | |
# Streamlit 页面设置 | |
st.title('AI Model API Interface') | |
st.write('输入文本,获取模型预测结果。') | |
# 用户输入 | |
user_input = st.text_area('请输入文本:') | |
if st.button('提交'): | |
if user_input.strip(): | |
with st.spinner('正在预测...'): | |
try: | |
response = requests.post( | |
'http://127.0.0.1:5000/predict', | |
json={'input': user_input} | |
) | |
if response.status_code == 200: | |
prediction = response.json() | |
st.success(f'预测结果: {prediction}') | |
else: | |
st.error(f'错误: {response.text}') | |
except Exception as e: | |
st.error(f'请求失败: {e}') | |
else: | |
st.warning('请输入文本!') | |