File size: 861 Bytes
547b48b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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('请输入文本!')