Spaces:
Runtime error
Runtime error
File size: 1,005 Bytes
ded7c37 7d707d7 11a5c67 ded7c37 7d707d7 ded7c37 1d49548 ded7c37 |
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 |
import gradio as gr
import requests
# 后端API地址(替换为你的实际地址)
BACKEND_URL = "https://dsbb0707-SpatialParse_back.hf.space/api/predict"
def call_backend(input_text):
try:
response = requests.post(
BACKEND_URL,
json={"data": [input_text]},
timeout=10
)
if response.status_code == 200:
result = response.json()["data"][0]
return f"✅ {result['result']}\n⏰ {result['timestamp']}"
return "❌ Backend Error"
except Exception as e:
return f"⚠️ Connection Error: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown("## Frontend Demo")
with gr.Row():
input_box = gr.Textbox(label="输入文本", placeholder="请输入...")
output_box = gr.Textbox(label="处理结果", interactive=False)
submit_btn = gr.Button("提交")
submit_btn.click(
fn=call_backend,
inputs=input_box,
outputs=output_box
)
demo.launch() |