Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def send_request(user_input):
|
| 5 |
+
url = 'https://songyou-llm-fastapi.hf.space/submit'
|
| 6 |
+
headers = {'Content-Type': 'application/json'}
|
| 7 |
+
data = {'user_input': user_input}
|
| 8 |
+
try:
|
| 9 |
+
response = requests.post(url, json=data, headers=headers)
|
| 10 |
+
response.raise_for_status()
|
| 11 |
+
result = response.json()
|
| 12 |
+
return result.get('message', 'No message received')
|
| 13 |
+
except requests.exceptions.RequestException as e:
|
| 14 |
+
return f'请求失败: {e}'
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=send_request,
|
| 18 |
+
inputs=gr.Textbox(label='输入文本'),
|
| 19 |
+
outputs=gr.Textbox(label='响应消息'),
|
| 20 |
+
title='Gradio 请求示例',
|
| 21 |
+
description='输入文本并点击提交,将请求发送到另一个 Space 的 API。'
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
iface.launch()
|