Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests # 缺少的模块导入
|
| 3 |
+
|
| 4 |
+
API_URL = 'https://ms-fc-eapp-func-wlddafkcou.cn-shanghai.fcapp.run/invoke'
|
| 5 |
+
|
| 6 |
+
def post_request(url, json):
|
| 7 |
+
with requests.Session() as session:
|
| 8 |
+
response = session.post(url, json=json)
|
| 9 |
+
return response
|
| 10 |
+
|
| 11 |
+
def backend_processing(text_input):
|
| 12 |
+
payload = {"input":{"text":text_input},"parameters":{}}
|
| 13 |
+
response = post_request(API_URL, json=payload)
|
| 14 |
+
response = response.json()
|
| 15 |
+
response = response['Data']['text']
|
| 16 |
+
return response # 修复缩进问题
|
| 17 |
+
|
| 18 |
+
# 使用gradio创建界面
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=backend_processing, # 后端处理函数
|
| 21 |
+
inputs="text", # 输入类型为文本
|
| 22 |
+
outputs="text", # 输出类型为文本
|
| 23 |
+
live=True, # 实时更新输出(如果适用)
|
| 24 |
+
title="简易文本处理示例", # 界面标题
|
| 25 |
+
description="输入文本,点击按钮,查看后端返回的信息。" # 界面描述
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# 启动界面
|
| 29 |
+
iface.launch(share=True)
|
| 30 |
+
|
| 31 |
+
# 以下的重复函数和调用应该被删除或注释掉
|
| 32 |
+
# def post_request(url, json):
|
| 33 |
+
# with requests.Session() as session:
|
| 34 |
+
# response = session.post(url, json=json)
|
| 35 |
+
# return response
|
| 36 |
+
# payload = {"input":{"text":"以关键词“五福”写一副春联"},"parameters":{}}
|
| 37 |
+
# response = post_request(API_URL, json=payload)
|