import gradio as gr import openai from create_db import create_db from chat import respond openai.api_base = "https://api.v36.cm/v1" # global setting is needed def launch_app(): with gr.Blocks() as demo: with gr.Row(equal_height=True): gr.Markdown("## 英语单词学习工具") with gr.Row(): with gr.Column(scale=4): chatbot = gr.Chatbot(height=400) msg = gr.Textbox(label="在此输入指令(以:起始)或对话") btn = gr.Button("Submit") gr.ClearButton(components=[msg, chatbot], value="清除对话") btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) with gr.Column(scale=1): file = gr.File(label='请导入制作词库的文件', file_count='single', file_types=['.md', '.pdf']) with gr.Row(): init_vocab_by_file = gr.Button("使用文件生成个人词库") text = gr.Textbox(label="在此粘贴制作词库的文本", lines=8) with gr.Row(): init_vocab_by_text = gr.Button("使用文本生成个人词库") init_vocab_by_file.click(create_db, inputs=[file, chatbot], outputs=[chatbot]) init_vocab_by_text.click(create_db, inputs=[text, chatbot], outputs=[chatbot]) gr.close_all() demo.launch() if __name__ == "__main__": launch_app()