Spaces:
Runtime error
Runtime error
File size: 1,181 Bytes
ded7c37 7d707d7 64daaee 11a5c67 7681731 64daaee 7d707d7 ded7c37 7681731 ded7c37 64daaee ded7c37 1d49548 ded7c37 a8939bc ded7c37 64daaee ded7c37 64daaee ded7c37 a8939bc 64daaee |
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 |
import gradio as gr
import requests
import os
API_TOKEN = os.getenv("HF_API_TOKEN")
BACKEND_URL = "https://your-backend-url/api/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)}"
with gr.Blocks() as demo:
gr.Markdown("## 地理信息识别系统")
with gr.Row():
input_box = gr.Textbox(label="输入描述文本")
output_box = gr.Textbox(label="识别结果", interactive=False)
submit_btn = gr.Button("提交")
submit_btn.click(fn=call_backend, inputs=input_box, outputs=output_box)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860) |