import gradio as gr import requests # 缺少的模块导入 API_URL = 'https://ms-fc-eapp-func-wlddafkcou.cn-shanghai.fcapp.run/invoke' def post_request(url, json): with requests.Session() as session: response = session.post(url, json=json) return response def backend_processing(text_input): payload = {"input":{"text":text_input},"parameters":{}} response = post_request(API_URL, json=payload) response = response.json() response = response['Data']['text'] return response # 修复缩进问题 # 使用gradio创建界面 iface = gr.Interface( fn=backend_processing, # 后端处理函数 inputs="text", # 输入类型为文本 outputs="text", # 输出类型为文本 live=True, # 实时更新输出(如果适用) title="简易文本处理示例", # 界面标题 description="输入文本,点击按钮,查看后端返回的信息。" # 界面描述 ) # 启动界面 iface.launch(share=True) # 以下的重复函数和调用应该被删除或注释掉 # def post_request(url, json): # with requests.Session() as session: # response = session.post(url, json=json) # return response # payload = {"input":{"text":"以关键词“五福”写一副春联"},"parameters":{}} # response = post_request(API_URL, json=payload)