Shunfeng Zheng commited on
Commit
ded7c37
·
verified ·
1 Parent(s): 5c8fd42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -16
app.py CHANGED
@@ -1,20 +1,34 @@
 
1
  import requests
2
- import streamlit as st
3
 
4
- st.title("Spatial Parser Demo")
 
5
 
6
- text = st.text_area("Enter your spatial description:")
7
-
8
- if st.button("Submit"):
9
- with st.spinner("Calling backend..."):
10
- try:
11
- response = requests.post(
12
- "https://dsbb0707--spatialparse-gradio.hf.space/run/predict",
13
- json={"data": [text]},
14
- timeout=20
15
- )
16
- st.write("Raw response:", response.text) # 调试信息
17
  result = response.json()["data"][0]
18
- st.success(f"Parsed Output:\n\n{result}")
19
- except Exception as e:
20
- st.error(f"Backend error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()