Spaces:
Runtime error
Runtime error
Shunfeng Zheng
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
-
|
5 |
-
BACKEND_URL = "https://dsbb0707-SpatialParse_back.hf.space/api/predict"
|
6 |
|
7 |
def call_backend(input_text):
|
8 |
try:
|
@@ -14,16 +13,17 @@ def call_backend(input_text):
|
|
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("##
|
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,
|
@@ -31,4 +31,6 @@ with gr.Blocks() as demo:
|
|
31 |
outputs=output_box
|
32 |
)
|
33 |
|
34 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
BACKEND_URL = "https://dsbb0707-SpatialParse_back.hf.space/api/predict/"
|
|
|
5 |
|
6 |
def call_backend(input_text):
|
7 |
try:
|
|
|
13 |
if response.status_code == 200:
|
14 |
result = response.json()["data"][0]
|
15 |
return f"✅ {result['result']}\n⏰ {result['timestamp']}"
|
16 |
+
return f"❌ Backend Error (HTTP {response.status_code})"
|
17 |
except Exception as e:
|
18 |
return f"⚠️ Connection Error: {str(e)}"
|
19 |
|
20 |
+
# Gradio界面构建
|
21 |
with gr.Blocks() as demo:
|
22 |
+
gr.Markdown("## 前端交互界面")
|
23 |
with gr.Row():
|
24 |
input_box = gr.Textbox(label="输入文本", placeholder="请输入...")
|
25 |
output_box = gr.Textbox(label="处理结果", interactive=False)
|
26 |
+
submit_btn = gr.Button("提交", variant="primary")
|
27 |
|
28 |
submit_btn.click(
|
29 |
fn=call_backend,
|
|
|
31 |
outputs=output_box
|
32 |
)
|
33 |
|
34 |
+
# 关键修改:使用正确的Gradio启动方式
|
35 |
+
if __name__ == "__main__":
|
36 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|