Spaces:
Runtime error
Runtime error
Shunfeng Zheng
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
|
|
| 1 |
import requests
|
| 2 |
-
import streamlit as st
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
timeout=20
|
| 15 |
-
)
|
| 16 |
-
st.write("Raw response:", response.text) # 调试信息
|
| 17 |
result = response.json()["data"][0]
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
+
# 后端API地址(替换为你的实际地址)
|
| 5 |
+
BACKEND_URL = "https://dsbb0707-SpatialParse_back.hf.space/api/predict"
|
| 6 |
|
| 7 |
+
def call_backend(input_text):
|
| 8 |
+
try:
|
| 9 |
+
response = requests.post(
|
| 10 |
+
BACKEND_URL,
|
| 11 |
+
json={"data": [input_text]},
|
| 12 |
+
timeout=10
|
| 13 |
+
)
|
| 14 |
+
if response.status_code == 200:
|
|
|
|
|
|
|
|
|
|
| 15 |
result = response.json()["data"][0]
|
| 16 |
+
return f"✅ {result['result']}\n⏰ {result['timestamp']}"
|
| 17 |
+
return "❌ Backend Error"
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"⚠️ Connection Error: {str(e)}"
|
| 20 |
+
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("## Frontend Demo")
|
| 23 |
+
with gr.Row():
|
| 24 |
+
input_box = gr.Textbox(label="输入文本", placeholder="请输入...")
|
| 25 |
+
output_box = gr.Textbox(label="处理结果", interactive=False)
|
| 26 |
+
submit_btn = gr.Button("提交")
|
| 27 |
+
|
| 28 |
+
submit_btn.click(
|
| 29 |
+
fn=call_backend,
|
| 30 |
+
inputs=input_box,
|
| 31 |
+
outputs=output_box
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|