aiZero 0.0.1a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ recursive-include aiZero/static *
2
+ recursive-include aiZero/templates *
@@ -0,0 +1,340 @@
1
+ Metadata-Version: 2.1
2
+ Name: aiZero
3
+ Version: 0.0.1a0
4
+ Summary: A simple and easy-to-use library that connects to common artificial intelligence interfaces, allowing for quick development of local web applications. It includes mainstream AI capabilities such as LLM text interaction, image understanding, audio understanding, image generation, speech recognition, and speech synthesis.
5
+ Home-page: UNKNOWN
6
+ Author: emhang
7
+ Author-email: emhang@126.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+
13
+ aiZero是一个简单易用的可以连接常用人工智能接口,快速搭建可视化本地web应用的Python第三方库,适配幻码人工智能初阶课程。
14
+
15
+ ### 快速开始
16
+
17
+ ```python
18
+ from aiZero import AIWebApp
19
+
20
+ # 设定web应用的功能
21
+ def my_ai_function():
22
+ pass
23
+
24
+ app = AIWebApp(title='人工智能助手') # 初始化web应用
25
+ app.set_apikey('YOUR_API_KEY') # 设定AI接口的api key
26
+ app.add_input_text() # 在页面中添加一个输入文本框
27
+ app.add_submit(my_ai_function) # 添加一个提交按钮,点击后执行函数
28
+ app.run(port=6060) # 启动应用,设定端口,默认为5000
29
+ ```
30
+
31
+ 启动后,你将可以在浏览器中访问http://127.0.0.1:6060/查看搭建好的web应用。
32
+
33
+ 如果需要实现AI功能的可视化呈现,你只需要将`'YOUR_API_KEY'`替换为真实的api key,并完善`my_ai_function`函数即可。
34
+
35
+ ### AI功能实现例子
36
+
37
+ #### 大模型文字交互
38
+
39
+ ##### 单轮对话
40
+
41
+ ```python
42
+ from aiZero import AIWebApp, text_generation
43
+
44
+ def my_ai_function():
45
+ text = app.input_text # 获取输入文本框的文字内容
46
+ reply = text_generation([text]) # 调用AI接口,获取回复反馈
47
+ app.results.append({'text': reply}) # 以文字形式将结果推送至前端
48
+
49
+ app = AIWebApp(title='人工智能助手')
50
+ app.set_apikey('YOUR_API_KEY')
51
+ app.add_input_text()
52
+ app.add_submit(my_ai_function)
53
+ app.run(port=6060)
54
+ ```
55
+
56
+ ##### 多轮对话
57
+
58
+ ```python
59
+ from aiZero import AIWebApp, text_generation
60
+
61
+ def my_ai_function():
62
+ text = app.input_text
63
+ chat_history.append(text) # 将输入内容添加到对话历史
64
+ reply = text_generation(chat_history)
65
+ chat_history.append(reply) # 将回复结果添加到对话历史
66
+ app.results.append({'text': reply})
67
+
68
+ chat_history = [] # 储存对话历史
69
+ app = AIWebApp(title='人工智能助手')
70
+ app.set_apikey('YOUR_API_KEY')
71
+ app.add_input_text()
72
+ app.add_submit(my_ai_function)
73
+ app.run(port=6060)
74
+ ```
75
+
76
+ ##### 设置系统指令
77
+
78
+ ```python
79
+ from aiZero import AIWebApp, text_generation
80
+
81
+ def my_ai_function():
82
+ text = app.input_text
83
+ chat_history.append(text)
84
+ # prompt参数可以设定系统指令,设定模型的行为要求
85
+ reply = text_generation(chat_history, prompt='你是一个10岁的小学生,名叫小幻')
86
+ chat_history.append(reply)
87
+ app.results.append({'text': reply})
88
+
89
+ chat_history = []
90
+ app = AIWebApp(title='人工智能助手')
91
+ app.set_apikey('YOUR_API_KEY')
92
+ app.add_input_text()
93
+ app.add_submit(my_ai_function)
94
+ app.run(port=6060)
95
+ ```
96
+
97
+ #### 图像理解
98
+
99
+ ##### 上传图片文件
100
+
101
+ ```python
102
+ from aiZero import AIWebApp, image_understanding
103
+
104
+ def my_ai_function():
105
+ text = app.input_text
106
+ img = app.input_pic # 获取上传的图片
107
+ reply = image_understanding(img, [text])
108
+ app.results.append({'text': reply})
109
+
110
+ chat_history = []
111
+ app = AIWebApp(title='人工智能助手')
112
+ app.set_apikey('YOUR_API_KEY')
113
+ app.add_input_text()
114
+ app.add_pic_file() # 添加一个图片文件上传按钮
115
+ app.add_submit(my_ai_function)
116
+ app.run(port=6060)
117
+ ```
118
+
119
+ ##### 摄像头捕获图像
120
+
121
+ ```python
122
+ from aiZero import AIWebApp, image_understanding
123
+
124
+ def my_ai_function():
125
+ text = app.input_text
126
+ img = app.input_pic # 获取捕获的图片
127
+ reply = image_understanding(img, [text])
128
+ app.results.append({'text': reply})
129
+
130
+ chat_history = []
131
+ app = AIWebApp(title='人工智能助手')
132
+ app.set_apikey('YOUR_API_KEY')
133
+ app.add_input_text()
134
+ app.add_camera() # 添加摄像头捕获窗口和按钮
135
+ app.add_submit(my_ai_function)
136
+ app.run(port=6060)
137
+ ```
138
+
139
+ #### 声音理解
140
+
141
+ ##### 上传音频文件
142
+
143
+ ```python
144
+ from aiZero import AIWebApp, audio_understanding
145
+
146
+ def my_ai_function():
147
+ text = app.input_text
148
+ audio = app.input_audio # 获取上传的音频
149
+ reply = audio_understanding(audio, [text])
150
+ app.results.append({'text': reply})
151
+
152
+ chat_history = []
153
+ app = AIWebApp(title='人工智能助手')
154
+ app.set_apikey('YOUR_API_KEY')
155
+ app.add_input_text()
156
+ app.add_audio_file() # 添加一个音频文件上传按钮
157
+ app.add_submit(my_ai_function)
158
+ app.run(port=6060)
159
+ ```
160
+
161
+ ##### 实时录音
162
+
163
+ ```python
164
+ from aiZero import AIWebApp, audio_understanding
165
+
166
+ def my_ai_function():
167
+ text = app.input_text
168
+ audio = app.input_audio # 获取录制的音频
169
+ reply = audio_understanding(audio, [text])
170
+ app.results.append({'text': reply})
171
+
172
+ chat_history = []
173
+ app = AIWebApp(title='人工智能助手')
174
+ app.set_apikey('YOUR_API_KEY')
175
+ app.add_input_text()
176
+ app.add_record() # 添加音频录制功能区
177
+ app.add_submit(my_ai_function)
178
+ app.run(port=6060)
179
+ ```
180
+
181
+ #### 图像生成
182
+
183
+ ```python
184
+ from aiZero import AIWebApp, image_generation
185
+
186
+ def my_ai_function():
187
+ text = app.input_text
188
+ reply = image_generation(text)
189
+ app.results.append({'image': reply}) # 将生成的图像推送到前端
190
+
191
+ app = AIWebApp(title='人工智能助手')
192
+ app.set_apikey('YOUR_API_KEY')
193
+ app.add_input_text()
194
+ app.add_submit(my_ai_function)
195
+ app.run(port=6060)
196
+ ```
197
+
198
+ #### 人物图像风格重绘
199
+
200
+ ```python
201
+ from aiZero import AIWebApp, human_repaint
202
+
203
+ def my_ai_function():
204
+ img = app.input_pic
205
+ reply = human_repaint(img)
206
+ app.results.append({'image': reply})
207
+
208
+ app = AIWebApp(title='人工智能助手')
209
+ app.set_apikey('YOUR_API_KEY')
210
+ app.add_camera()
211
+ app.add_submit(my_ai_function)
212
+ app.run(port=6060)
213
+ ```
214
+
215
+ 以上例程为使用摄像头采集图像,也可以改为上传图片文件。
216
+
217
+ `human_repaint`函数可以接受`style`参数设定风格类型,可选值为0~9的数字(默认值为7)。
218
+
219
+ #### 涂鸦作画
220
+
221
+ ```python
222
+ from aiZero import AIWebApp, sketch_to_image
223
+
224
+ def my_ai_function():
225
+ text = app.input_text # 涂鸦作画的提示文字
226
+ img = app.input_pic # 涂鸦草图图像
227
+ reply = sketch_to_image(img, text)
228
+ app.results.append({'image': reply})
229
+
230
+ app = AIWebApp(title='人工智能助手')
231
+ app.set_apikey('YOUR_API_KEY')
232
+ app.add_input_text()
233
+ app.add_pic_file()
234
+ app.add_submit(my_ai_function)
235
+ app.run(port=6060)
236
+ ```
237
+
238
+ 以上例程为上传图片文件,也可以改为用摄像头捕获图像。
239
+
240
+ `sktech_to_image`函数可以接受`style`参数设定风格类型,包括:
241
+
242
+ - `"<3d cartoon>"`:3D 卡通
243
+ - `"<anime>"`:二次元(默认值)
244
+ - `"<oil painting>"`:油画
245
+ - `"<watercolor>"` :水彩
246
+ - `"<flat illustration>"`:扁平插画
247
+
248
+ #### 语音识别
249
+
250
+ ```python
251
+ from aiZero import AIWebApp, speech_recognition
252
+
253
+ def my_ai_function():
254
+ audio = app.input_audio
255
+ reply = speech_recognition(audio)
256
+ app.results.append({'text': reply})
257
+
258
+ app = AIWebApp(title='人工智能助手')
259
+ app.set_apikey('YOUR_API_KEY')
260
+ app.add_record()
261
+ app.add_submit(my_ai_function)
262
+ app.run(port=6060)
263
+ ```
264
+
265
+ 所用接口支持中英文双语的语音识别。以上例程为实时录音,也可以改为上传录音音频文件。
266
+
267
+ #### 语音合成
268
+
269
+ ```python
270
+ from aiZero import AIWebApp, speech_synthesis
271
+
272
+ def my_ai_function():
273
+ text = app.input_text
274
+ reply = speech_synthesis(text)
275
+ app.results.append({'audio': reply}) # 将音频结果推送到前端
276
+
277
+ app = AIWebApp(title='人工智能助手')
278
+ app.set_apikey('YOUR_API_KEY')
279
+ app.add_input_text()
280
+ app.add_submit(my_ai_function)
281
+ app.run(port=6060)
282
+ ```
283
+
284
+ `speech_synthesis`函数可以接受以下参数:
285
+
286
+ - `model`:设定使用的语音模型,详细列表参见[链接](https://help.aliyun.com/zh/dashscope/model-list)。
287
+ - `rate`:设定语速快慢,取值范围0.5~2,默认值为1。
288
+ - `pitch`:设定语调高低,取值范围0.5~2,默认值为1。
289
+
290
+ ### 进阶使用
291
+
292
+ #### 多种AI功能的混合
293
+
294
+ aiZero支持方便地将不同的AI功能进行链式整合,例如,将文字交互、语音识别、语音合成结合起来,可以实现语音交互。
295
+
296
+ ```python
297
+ from aiZero import AIWebApp, text_generation, speech_recognition, speech_synthesis
298
+
299
+ def my_ai_function():
300
+ audio = app.input_audio
301
+ text = speech_recognition(audio)
302
+ chat_history.append(text)
303
+ reply = text_generation([text])
304
+ chat_history.append(reply)
305
+ reply_audio = speech_synthesis(reply)
306
+ app.results.append({'audio': reply_audio})
307
+
308
+ chat_history = []
309
+ app = AIWebApp(title='人工智能助手')
310
+ app.set_apikey('YOUR_API_KEY')
311
+ app.add_record()
312
+ app.add_submit(my_ai_function)
313
+ app.run(port=6060)
314
+ ```
315
+
316
+ #### 同时输出多种不同类型的信息
317
+
318
+ aiZero支持输出文字、音频和图像等多种不同类型的信息,但每种类型的信息只能为一个(即不支持一次性输出2张图像、2段音频),且必须同时推送到前端。例如,我们可以输入文字,同时以文本和音频形式输出AI的响应。
319
+
320
+ ```python
321
+ from aiZero import AIWebApp, text_generation, speech_synthesis
322
+
323
+ def my_ai_function():
324
+ text = app.input_text
325
+ chat_history.append(text)
326
+ reply = text_generation([text])
327
+ chat_history.append(reply)
328
+ reply_audio = speech_synthesis(reply)
329
+ app.results.append({'text': reply, 'audio': reply_audio})
330
+
331
+ chat_history = []
332
+ app = AIWebApp(title='人工智能助手')
333
+ app.set_apikey('YOUR_API_KEY')
334
+ app.add_input_text()
335
+ app.add_submit(my_ai_function)
336
+ app.run(port=6060)
337
+ ```
338
+
339
+
340
+
@@ -0,0 +1,326 @@
1
+ aiZero是一个简单易用的可以连接常用人工智能接口,快速搭建可视化本地web应用的Python第三方库,适配幻码人工智能初阶课程。
2
+
3
+ ### 快速开始
4
+
5
+ ```python
6
+ from aiZero import AIWebApp
7
+
8
+ # 设定web应用的功能
9
+ def my_ai_function():
10
+ pass
11
+
12
+ app = AIWebApp(title='人工智能助手') # 初始化web应用
13
+ app.set_apikey('YOUR_API_KEY') # 设定AI接口的api key
14
+ app.add_input_text() # 在页面中添加一个输入文本框
15
+ app.add_submit(my_ai_function) # 添加一个提交按钮,点击后执行函数
16
+ app.run(port=6060) # 启动应用,设定端口,默认为5000
17
+ ```
18
+
19
+ 启动后,你将可以在浏览器中访问http://127.0.0.1:6060/查看搭建好的web应用。
20
+
21
+ 如果需要实现AI功能的可视化呈现,你只需要将`'YOUR_API_KEY'`替换为真实的api key,并完善`my_ai_function`函数即可。
22
+
23
+ ### AI功能实现例子
24
+
25
+ #### 大模型文字交互
26
+
27
+ ##### 单轮对话
28
+
29
+ ```python
30
+ from aiZero import AIWebApp, text_generation
31
+
32
+ def my_ai_function():
33
+ text = app.input_text # 获取输入文本框的文字内容
34
+ reply = text_generation([text]) # 调用AI接口,获取回复反馈
35
+ app.results.append({'text': reply}) # 以文字形式将结果推送至前端
36
+
37
+ app = AIWebApp(title='人工智能助手')
38
+ app.set_apikey('YOUR_API_KEY')
39
+ app.add_input_text()
40
+ app.add_submit(my_ai_function)
41
+ app.run(port=6060)
42
+ ```
43
+
44
+ ##### 多轮对话
45
+
46
+ ```python
47
+ from aiZero import AIWebApp, text_generation
48
+
49
+ def my_ai_function():
50
+ text = app.input_text
51
+ chat_history.append(text) # 将输入内容添加到对话历史
52
+ reply = text_generation(chat_history)
53
+ chat_history.append(reply) # 将回复结果添加到对话历史
54
+ app.results.append({'text': reply})
55
+
56
+ chat_history = [] # 储存对话历史
57
+ app = AIWebApp(title='人工智能助手')
58
+ app.set_apikey('YOUR_API_KEY')
59
+ app.add_input_text()
60
+ app.add_submit(my_ai_function)
61
+ app.run(port=6060)
62
+ ```
63
+
64
+ ##### 设置系统指令
65
+
66
+ ```python
67
+ from aiZero import AIWebApp, text_generation
68
+
69
+ def my_ai_function():
70
+ text = app.input_text
71
+ chat_history.append(text)
72
+ # prompt参数可以设定系统指令,设定模型的行为要求
73
+ reply = text_generation(chat_history, prompt='你是一个10岁的小学生,名叫小幻')
74
+ chat_history.append(reply)
75
+ app.results.append({'text': reply})
76
+
77
+ chat_history = []
78
+ app = AIWebApp(title='人工智能助手')
79
+ app.set_apikey('YOUR_API_KEY')
80
+ app.add_input_text()
81
+ app.add_submit(my_ai_function)
82
+ app.run(port=6060)
83
+ ```
84
+
85
+ #### 图像理解
86
+
87
+ ##### 上传图片文件
88
+
89
+ ```python
90
+ from aiZero import AIWebApp, image_understanding
91
+
92
+ def my_ai_function():
93
+ text = app.input_text
94
+ img = app.input_pic # 获取上传的图片
95
+ reply = image_understanding(img, [text])
96
+ app.results.append({'text': reply})
97
+
98
+ chat_history = []
99
+ app = AIWebApp(title='人工智能助手')
100
+ app.set_apikey('YOUR_API_KEY')
101
+ app.add_input_text()
102
+ app.add_pic_file() # 添加一个图片文件上传按钮
103
+ app.add_submit(my_ai_function)
104
+ app.run(port=6060)
105
+ ```
106
+
107
+ ##### 摄像头捕获图像
108
+
109
+ ```python
110
+ from aiZero import AIWebApp, image_understanding
111
+
112
+ def my_ai_function():
113
+ text = app.input_text
114
+ img = app.input_pic # 获取捕获的图片
115
+ reply = image_understanding(img, [text])
116
+ app.results.append({'text': reply})
117
+
118
+ chat_history = []
119
+ app = AIWebApp(title='人工智能助手')
120
+ app.set_apikey('YOUR_API_KEY')
121
+ app.add_input_text()
122
+ app.add_camera() # 添加摄像头捕获窗口和按钮
123
+ app.add_submit(my_ai_function)
124
+ app.run(port=6060)
125
+ ```
126
+
127
+ #### 声音理解
128
+
129
+ ##### 上传音频文件
130
+
131
+ ```python
132
+ from aiZero import AIWebApp, audio_understanding
133
+
134
+ def my_ai_function():
135
+ text = app.input_text
136
+ audio = app.input_audio # 获取上传的音频
137
+ reply = audio_understanding(audio, [text])
138
+ app.results.append({'text': reply})
139
+
140
+ chat_history = []
141
+ app = AIWebApp(title='人工智能助手')
142
+ app.set_apikey('YOUR_API_KEY')
143
+ app.add_input_text()
144
+ app.add_audio_file() # 添加一个音频文件上传按钮
145
+ app.add_submit(my_ai_function)
146
+ app.run(port=6060)
147
+ ```
148
+
149
+ ##### 实时录音
150
+
151
+ ```python
152
+ from aiZero import AIWebApp, audio_understanding
153
+
154
+ def my_ai_function():
155
+ text = app.input_text
156
+ audio = app.input_audio # 获取录制的音频
157
+ reply = audio_understanding(audio, [text])
158
+ app.results.append({'text': reply})
159
+
160
+ chat_history = []
161
+ app = AIWebApp(title='人工智能助手')
162
+ app.set_apikey('YOUR_API_KEY')
163
+ app.add_input_text()
164
+ app.add_record() # 添加音频录制功能区
165
+ app.add_submit(my_ai_function)
166
+ app.run(port=6060)
167
+ ```
168
+
169
+ #### 图像生成
170
+
171
+ ```python
172
+ from aiZero import AIWebApp, image_generation
173
+
174
+ def my_ai_function():
175
+ text = app.input_text
176
+ reply = image_generation(text)
177
+ app.results.append({'image': reply}) # 将生成的图像推送到前端
178
+
179
+ app = AIWebApp(title='人工智能助手')
180
+ app.set_apikey('YOUR_API_KEY')
181
+ app.add_input_text()
182
+ app.add_submit(my_ai_function)
183
+ app.run(port=6060)
184
+ ```
185
+
186
+ #### 人物图像风格重绘
187
+
188
+ ```python
189
+ from aiZero import AIWebApp, human_repaint
190
+
191
+ def my_ai_function():
192
+ img = app.input_pic
193
+ reply = human_repaint(img)
194
+ app.results.append({'image': reply})
195
+
196
+ app = AIWebApp(title='人工智能助手')
197
+ app.set_apikey('YOUR_API_KEY')
198
+ app.add_camera()
199
+ app.add_submit(my_ai_function)
200
+ app.run(port=6060)
201
+ ```
202
+
203
+ 以上例程为使用摄像头采集图像,也可以改为上传图片文件。
204
+
205
+ `human_repaint`函数可以接受`style`参数设定风格类型,可选值为0~9的数字(默认值为7)。
206
+
207
+ #### 涂鸦作画
208
+
209
+ ```python
210
+ from aiZero import AIWebApp, sketch_to_image
211
+
212
+ def my_ai_function():
213
+ text = app.input_text # 涂鸦作画的提示文字
214
+ img = app.input_pic # 涂鸦草图图像
215
+ reply = sketch_to_image(img, text)
216
+ app.results.append({'image': reply})
217
+
218
+ app = AIWebApp(title='人工智能助手')
219
+ app.set_apikey('YOUR_API_KEY')
220
+ app.add_input_text()
221
+ app.add_pic_file()
222
+ app.add_submit(my_ai_function)
223
+ app.run(port=6060)
224
+ ```
225
+
226
+ 以上例程为上传图片文件,也可以改为用摄像头捕获图像。
227
+
228
+ `sktech_to_image`函数可以接受`style`参数设定风格类型,包括:
229
+
230
+ - `"<3d cartoon>"`:3D 卡通
231
+ - `"<anime>"`:二次元(默认值)
232
+ - `"<oil painting>"`:油画
233
+ - `"<watercolor>"` :水彩
234
+ - `"<flat illustration>"`:扁平插画
235
+
236
+ #### 语音识别
237
+
238
+ ```python
239
+ from aiZero import AIWebApp, speech_recognition
240
+
241
+ def my_ai_function():
242
+ audio = app.input_audio
243
+ reply = speech_recognition(audio)
244
+ app.results.append({'text': reply})
245
+
246
+ app = AIWebApp(title='人工智能助手')
247
+ app.set_apikey('YOUR_API_KEY')
248
+ app.add_record()
249
+ app.add_submit(my_ai_function)
250
+ app.run(port=6060)
251
+ ```
252
+
253
+ 所用接口支持中英文双语的语音识别。以上例程为实时录音,也可以改为上传录音音频文件。
254
+
255
+ #### 语音合成
256
+
257
+ ```python
258
+ from aiZero import AIWebApp, speech_synthesis
259
+
260
+ def my_ai_function():
261
+ text = app.input_text
262
+ reply = speech_synthesis(text)
263
+ app.results.append({'audio': reply}) # 将音频结果推送到前端
264
+
265
+ app = AIWebApp(title='人工智能助手')
266
+ app.set_apikey('YOUR_API_KEY')
267
+ app.add_input_text()
268
+ app.add_submit(my_ai_function)
269
+ app.run(port=6060)
270
+ ```
271
+
272
+ `speech_synthesis`函数可以接受以下参数:
273
+
274
+ - `model`:设定使用的语音模型,详细列表参见[链接](https://help.aliyun.com/zh/dashscope/model-list)。
275
+ - `rate`:设定语速快慢,取值范围0.5~2,默认值为1。
276
+ - `pitch`:设定语调高低,取值范围0.5~2,默认值为1。
277
+
278
+ ### 进阶使用
279
+
280
+ #### 多种AI功能的混合
281
+
282
+ aiZero支持方便地将不同的AI功能进行链式整合,例如,将文字交互、语音识别、语音合成结合起来,可以实现语音交互。
283
+
284
+ ```python
285
+ from aiZero import AIWebApp, text_generation, speech_recognition, speech_synthesis
286
+
287
+ def my_ai_function():
288
+ audio = app.input_audio
289
+ text = speech_recognition(audio)
290
+ chat_history.append(text)
291
+ reply = text_generation([text])
292
+ chat_history.append(reply)
293
+ reply_audio = speech_synthesis(reply)
294
+ app.results.append({'audio': reply_audio})
295
+
296
+ chat_history = []
297
+ app = AIWebApp(title='人工智能助手')
298
+ app.set_apikey('YOUR_API_KEY')
299
+ app.add_record()
300
+ app.add_submit(my_ai_function)
301
+ app.run(port=6060)
302
+ ```
303
+
304
+ #### 同时输出多种不同类型的信息
305
+
306
+ aiZero支持输出文字、音频和图像等多种不同类型的信息,但每种类型的信息只能为一个(即不支持一次性输出2张图像、2段音频),且必须同时推送到前端。例如,我们可以输入文字,同时以文本和音频形式输出AI的响应。
307
+
308
+ ```python
309
+ from aiZero import AIWebApp, text_generation, speech_synthesis
310
+
311
+ def my_ai_function():
312
+ text = app.input_text
313
+ chat_history.append(text)
314
+ reply = text_generation([text])
315
+ chat_history.append(reply)
316
+ reply_audio = speech_synthesis(reply)
317
+ app.results.append({'text': reply, 'audio': reply_audio})
318
+
319
+ chat_history = []
320
+ app = AIWebApp(title='人工智能助手')
321
+ app.set_apikey('YOUR_API_KEY')
322
+ app.add_input_text()
323
+ app.add_submit(my_ai_function)
324
+ app.run(port=6060)
325
+ ```
326
+