Spaces:
Running
Running
Change to Gradio
Browse files
app.py
CHANGED
@@ -1,21 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
-
from pydantic import BaseModel
|
3 |
|
4 |
-
#
|
5 |
-
def
|
6 |
-
|
7 |
-
result = text + " (preprocessed)"
|
8 |
-
return {"result": result}
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
inputs="text",
|
14 |
-
outputs="
|
15 |
-
title="
|
16 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
)
|
18 |
|
19 |
-
# 运行 Gradio 应用
|
20 |
if __name__ == "__main__":
|
21 |
-
|
|
|
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()
|