A simple and easy-to-use library that connects to common artificial intelligence interfaces (powered by Gradio), 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.
Project description
aiZero-gr是一个简单易用的可以连接常用人工智能接口,快速搭建可视化本地web应用的Python第三方库,在aiZero库的基础上,调整为基于gradio框架的界面展示。
当前版本仅支持阿里云灵积模型服务的api key和有限的功能调用,且暂不支持流式输出。本文档只包含基础功能的示例,进阶使用技巧可以参照aiZero库的文档内容。
快速开始
from aiZero_gr import AIWebApp
# 设定web应用的功能
def my_ai_function():
pass
app = AIWebApp(title='人工智能助手') # 初始化web应用
app.set_apikey('YOUR_API_KEY') # 设定AI接口的api key
app.add_input_text() # 在页面中添加一个输入文本框
app.add_submit(my_ai_function) # 设定提交按钮点击后执行的函数功能
app.run() # 启动应用
启动后,程序将自动输出本地网址,你将可以在浏览器中访问并查看搭建好的web应用。
如果需要实现AI功能的可视化呈现,你只需要将'YOUR_API_KEY'
替换为真实的api key,并完善my_ai_function
函数。
AI功能实现例子
大模型文字交互
单轮对话
from aiZero_gr import AIWebApp, text_generation
def my_ai_function():
text = app.input_text # 获取输入文本框的文字内容
reply = text_generation(text) # 调用AI接口,获取回复反馈
app.results['text'] = reply # 以文字形式将结果推送至前端
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_submit(my_ai_function)
app.run()
多轮对话
from aiZero_gr import AIWebApp, text_generation
def my_ai_function():
text = app.input_text
history = app.chat_history # 获取对话历史记录
reply = text_generation(text, history) # 将历史记录同时提交
app.results['text'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_submit(my_ai_function)
app.run()
设置系统指令
from aiZero_gr import AIWebApp, text_generation
def my_ai_function():
text = app.input_text
history = app.chat_history
# prompt参数可以设定系统指令,设定模型的行为要求
reply = text_generation(text, history, prompt='你是一个10岁的小学生,名叫小幻')
app.results['text'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_submit(my_ai_function)
app.run()
图像理解
from aiZero_gr import AIWebApp, image_understanding
def my_ai_function():
text = app.input_text
img = app.input_pic # 获取输入的图像
history = app.chat_history
reply = image_understanding(img, text, history)
app.results['text'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_input_pic() # 添加图像输入组件
app.add_submit(my_ai_function)
app.run()
声音理解
from aiZero_gr import AIWebApp, audio_understanding
def my_ai_function():
text = app.input_text
audio = app.input_audio # 获取输入的音频
history = app.chat_history
reply = audio_understanding(audio, text, history)
app.results['text'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_input_audio() # 添加音频输入组件
app.add_submit(my_ai_function)
app.run()
图像生成
from aiZero_gr import AIWebApp, image_generation
def my_ai_function():
text = app.input_text
reply = image_generation(text)
app.results['image'] = reply # 将生成的图像推送到前端
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_submit(my_ai_function)
app.run()
人物图像风格重绘
from aiZero_gr import AIWebApp, human_repaint
def my_ai_function():
img = app.input_pic
reply = human_repaint(img)
app.results['image'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_pic()
app.add_submit(my_ai_function)
app.run()
human_repaint
函数可以接受style
参数设定风格类型,可选值为0~9的数字(默认值为7)。
涂鸦作画
from aiZero_gr import AIWebApp, sketch_to_image
def my_ai_function():
text = app.input_text # 涂鸦作画的提示文字
img = app.input_pic # 涂鸦草图图像
reply = sketch_to_image(img, text)
app.results['image'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_input_pic()
app.add_submit(my_ai_function)
app.run()
sktech_to_image
函数可以接受style
参数设定风格类型,包括:
"<3d cartoon>"
:3D 卡通"<anime>"
:二次元(默认值)"<oil painting>"
:油画"<watercolor>"
:水彩"<flat illustration>"
:扁平插画
语音识别
from aiZero_gr import AIWebApp, speech_recognition
def my_ai_function():
audio = app.input_audio
reply = speech_recognition(audio)
app.results['text'] = reply
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_audio()
app.add_submit(my_ai_function)
app.run()
所用接口支持中英文双语的语音识别。
语音合成
from aiZero_gr import AIWebApp, speech_synthesis
def my_ai_function():
text = app.input_text
reply = speech_synthesis(text)
app.results['audio'] = reply # 将音频结果推送到前端
app = AIWebApp(title='人工智能助手')
app.set_apikey('YOUR_API_KEY')
app.add_input_text()
app.add_submit(my_ai_function)
app.run()
speech_synthesis
函数可以接受以下参数:
rate
:设定语速快慢,取值范围0.5~2,默认值为1。pitch
:设定语调高低,取值范围0.5~2,默认值为1。voice
:设定使用的音色,详细列表参见链接。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiZero-gr-0.0.1a1.tar.gz
.
File metadata
- Download URL: aiZero-gr-0.0.1a1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a62f2b1f433c1d64c24c9693ea02d778f0f20e33edf45443491f2d3fa705e6da |
|
MD5 | 11d404c47d3b1f70d0011fc40823199d |
|
BLAKE2b-256 | f7f2ddb3dd92a797e4b9508176701395d546930c8fbad59174f858a533c283d8 |
File details
Details for the file aiZero_gr-0.0.1a1-py3-none-any.whl
.
File metadata
- Download URL: aiZero_gr-0.0.1a1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8cdc4235e063337b4bd9d6c696aa055f62c4658d9c9028b0fef4af2a3bd9391 |
|
MD5 | b574708f3b4327727832d0c491ad2d53 |
|
BLAKE2b-256 | 8d32a3f573f5bfc842b217f9a40ed600b9e79a556ee3b4fe9865c4e2b2c6dcc0 |