parkerjj commited on
Commit
834b75c
·
1 Parent(s): 13ee506

Change to Gradio

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -1,21 +1,34 @@
1
  import gradio as gr
2
- from pydantic import BaseModel
3
 
4
- # 定义 Gradio 接口
5
- def gradio_interface(text):
6
- # 在这里实现实际的预处理逻辑
7
- result = text + " (preprocessed)"
8
- return {"result": result}
9
 
10
- # 配置 Gradio 接口
11
- iface = gr.Interface(
12
- fn=gradio_interface,
 
 
 
 
 
 
 
 
 
 
 
13
  inputs="text",
14
- outputs="json",
15
- title="文本预处理 API",
16
- description="发送文本到 Gradio 接口进行预处理并获取 JSON 格式的响应"
 
 
 
 
 
 
17
  )
18
 
19
- # 运行 Gradio 应用
20
  if __name__ == "__main__":
21
- iface.launch()
 
1
  import gradio as gr
 
2
 
3
+ # 定义两个简单的文本处理函数
4
+ def process_aaa(text):
5
+ return text + 'aaa'
 
 
6
 
7
+ def process_bbb(text):
8
+ return text + 'bbb'
9
+
10
+ # 创建两个 Gradio 接口
11
+ iface_aaa = gr.Interface(
12
+ fn=process_aaa,
13
+ inputs="text",
14
+ outputs="text",
15
+ title="API for /api/aaa",
16
+ description="输入文本并返回文本 + 'aaa'"
17
+ )
18
+
19
+ iface_bbb = gr.Interface(
20
+ fn=process_bbb,
21
  inputs="text",
22
+ outputs="text",
23
+ title="API for /api/bbb",
24
+ description="输入文本并返回文本 + 'bbb'"
25
+ )
26
+
27
+ # 启动 Gradio 应用,包含两个子接口
28
+ demo = gr.TabbedInterface(
29
+ [iface_aaa, iface_bbb],
30
+ ["API /api/aaa", "API /api/bbb"]
31
  )
32
 
 
33
  if __name__ == "__main__":
34
+ demo.launch()