File size: 1,479 Bytes
5f9c4de
7abe057
5f9c4de
7abe057
5f9c4de
7abe057
 
5f9c4de
b298d7c
 
7abe057
 
 
 
 
 
 
5f9c4de
7abe057
 
 
 
 
 
 
 
 
 
5f9c4de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7abe057
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
import streamlit as st
import requests
import os

# ✅ 从 Hugging Face Secrets 中读取 API Token
API_TOKEN = os.getenv("HF_API_TOKEN")

# ✅ 设置后端 API 地址
# BACKEND_URL = "https://dsbb0707-SpatialParsebackcopy.hf.space/api/predict/"
BACKEND_URL = "https://dsbb0707--dockerb2.hf.space/predict"
def call_backend(input_text):
    try:
        headers = {
            "Authorization": f"Bearer {API_TOKEN}"
        }
        response = requests.post(
            BACKEND_URL,
            headers=headers,
            json={"data": [input_text]},
            timeout=10
        )
        if response.status_code == 200:
            result = response.json()["data"][0]
            return f"✅ {result['result']}\n⏰ {result['timestamp']}"
        return f"❌ Backend Error (HTTP {response.status_code})"
    except Exception as e:
        return f"⚠️ Connection Error: {str(e)}"

# ✅ Streamlit UI 界面
st.set_page_config(page_title="空间信息前端", page_icon="🧠")
st.title("🌏 空间解析前端")
st.markdown("通过 Hugging Face API 与后端交互")

# ✅ 用户输入
user_input = st.text_input("请输入文本", "")

# ✅ 提交按钮
if st.button("提交"):
    if not user_input.strip():
        st.warning("请先输入文本。")
    else:
        with st.spinner("🔄 正在调用后端..."):
            result = call_backend(user_input)
        st.success("完成!")
        st.text_area("后端返回结果", result, height=150)