Spaces:
Runtime error
Runtime error
import gradio as gr | |
from sdk.Chat_with_memory import Conversation | |
from sdk.culculate import Cuculator | |
from sdk.chat_with_net import ChatWithNet | |
from api.chatText2ImageQuery import DrawAssistant | |
from sdk.textSummary import SummaryAssistant | |
from sdk.chatWithKnowledgeBase import KnowledgeBaseAssistant | |
import tempfile | |
chat = Conversation() | |
culculator = Cuculator() | |
chatWithNet = ChatWithNet() | |
drawAssistant = DrawAssistant() | |
summaryAssistant = SummaryAssistant() | |
KnowledgeBaseAssistant = KnowledgeBaseAssistant() | |
with gr.Blocks() as myAIBox: | |
with gr.Tab("AI聊天助手"): | |
#Blocks特有组件,设置所有子组件按垂直排列 | |
#垂直排列是默认情况,不加也没关系 | |
with gr.Column(): | |
text_input = gr.Textbox(label="请输入你的问题") | |
chatbot = gr.Chatbot() | |
ask = gr.Button("一键答疑") | |
ask.click(chat.ask,text_input,chatbot) | |
clearHistory = gr.Button("清空当前搜索结果") | |
clearHistory.click(chat.clearHistory,None,chatbot, queue=False) | |
with gr.Tab("智能计算器"): | |
# Blocks特有组件,设置所有子组件按水平排列 | |
with gr.Column(): | |
math_input = gr.Textbox(label="请输入你的问题") | |
CulChatbot = gr.Chatbot() | |
ask = gr.Button("生成答案") | |
ask.click(culculator.culculate,math_input,CulChatbot) | |
clearHistory = gr.Button("清空当前搜索结果") | |
clearHistory.click(culculator.clearHistory,None,CulChatbot, queue=False) | |
with gr.Tab("联网问答"): | |
# Blocks特有组件,设置所有子组件按水平排列 | |
with gr.Column(): | |
text_input = gr.Textbox(label="请输入你的问题") | |
NetChatbot = gr.Chatbot() | |
ask = gr.Button("谷歌搜索问答") | |
ask.click(chatWithNet.searhAndChat,text_input,NetChatbot) | |
clearHistory = gr.Button("清空当前搜索结果") | |
clearHistory.click(chatWithNet.searhAndChat,None,NetChatbot) | |
with gr.Tab("绘图助手"): | |
# Blocks特有组件,设置所有子组件按水平排列 | |
with gr.Row(): | |
text_input = gr.Textbox(label="请输入你希望画的图片及其细节(生成图片较慢,请耐心等待)") | |
image_output = gr.Image() | |
ask = gr.Button("生成图片") | |
ask.click(drawAssistant.drawOnePic,text_input,image_output ) | |
clearPic = gr.Button("清空当前搜索结果") | |
clearPic.click(None,None,image_output, queue=False) | |
with gr.Tab("文本总结器"): | |
# Blocks特有组件,设置所有子组件按水平排列 | |
global tmpdir | |
with tempfile.TemporaryDirectory() as tmpdir: | |
with gr.Column(): | |
with gr.Row(): | |
summary_text_input = gr.Textbox(label="请输入你希望总结的文本") | |
summary_output = gr.Textbox(label="总结文本") | |
send_btn = gr.Button("对文本生成总结") | |
send_btn.click(summaryAssistant.summary_text,summary_text_input,summary_output) | |
with gr.Row(): | |
summary_url_input = gr.Textbox(label="请输入你希望总结的网页") | |
summary_output2 = gr.Textbox(label="网页地址") | |
send_btn2 = gr.Button("对网页生成总结") | |
send_btn2.click(summaryAssistant.summary_url,summary_url_input,summary_output2) | |
with gr.Row(): | |
summary_file_input = gr.components.File(label="请输入你希望总结的文本文件(现在仅支持txt,pdf,word格式)") | |
summary_output3 = gr.Textbox(label="总结文本") | |
send_btn3 = gr.Button("对文件生成总结") | |
send_btn3.click(summaryAssistant.summary_file,summary_file_input,summary_output3) | |
with gr.Tab("个人知识库"): | |
# Blocks特有组件,设置所有子组件按水平排列 | |
with gr.Column(scale=4): | |
with gr.Row(): | |
knowledge_text_input = gr.Textbox(label="请输入你的知识库的文本") | |
q_input = gr.Textbox(label="请输入你的问题") | |
res_output = gr.Textbox(label="结果输出") | |
s_btn = gr.Button("一键问答") | |
s_btn.click(KnowledgeBaseAssistant.knowledge_base_text,[knowledge_text_input,q_input],res_output) | |
with gr.Row(): | |
knowledge_URL_input = gr.Textbox(label="请输入你的网页链接") | |
q2_input = gr.Textbox(label="请输入你的问题") | |
res2_output = gr.Textbox(label="结果输出") | |
s2_btn = gr.Button("一键问答") | |
s2_btn.click(KnowledgeBaseAssistant.knowledge_base_url,[knowledge_URL_input,q2_input],res2_output) | |
with gr.Row(): | |
knowledge_file_input = gr.components.File(label="请输入你的知识库文本(现在仅支持txt,pdf,word格式)") | |
q3_input = gr.Textbox(label="请输入你的问题") | |
res3_output = gr.Textbox(label="结果输出") | |
s3_btn = gr.Button("一键问答") | |
s3_btn.click(KnowledgeBaseAssistant.knowledge_base_file,[knowledge_file_input,q3_input],res3_output) | |
if __name__ == "__main__": | |
myAIBox.launch(share=True) | |