File size: 2,025 Bytes
f017ec1
 
 
7abe057
f017ec1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
# 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)

import gradio as gr
import time  # 模拟处理耗时

def process_api(input_text):
    # 这里编写实际的后端处理逻辑
    time.sleep(1)  # 模拟处理延迟
    return {
        "status": "success",
        "result": f"Processed: {input_text.upper()}",
        "timestamp": time.time()
    }

# 设置API格式为JSON
gr.Interface(
    fn=process_api,
    inputs="text",
    outputs="json",
    title="Backend API",
    allow_flagging="never"
).launch()