import gradio as gr from llm import OpenAI3, OpenAI4 from app_com.generate_paper import generate_paper from app_com.reading_comprehension import text_generate, files_generate from app_com.correct_assay import text_correct, files_correct block_css = """ .importantButton { background: linear-gradient(45deg, #7e0570,#5d1c99, #6e00ff) !important; border: none !important; } .importantButton:hover { background: linear-gradient(45deg, #ff00e0,#8500ff, #6e00ff) !important; border: none !important; }""" webui_title = "📚📚📚📚📚📚📚📚📚📚📚📚* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ☘️ * * *智能组卷助手* * * ☘️ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *📚📚📚📚📚📚📚📚📚📚📚📚" llm_name_dict = {'chatgpt-3.5': 'OpenAI3', 'chatgpt-4': 'OpenAI4', 'chatglm—6b': 'ChatGLM'} def llm_change(name): llm = eval(eval('llm_name_dict[name]'))() return llm def clear_screen(chatbot): return [[None, None]] def function_select(mode): if mode == "试卷生成": return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False) elif mode == "阅读理解生成": return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False) else: return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True) with gr.Blocks(css=block_css) as demo: gr.Markdown('\n\n\n\n') gr.Markdown(webui_title) gr.Markdown('\n\n\n\n') llm = gr.State('') model_mode = gr.Radio(["chatgpt-3.5", "chatgpt-4"], label="请选择驱动模型") model_mode.change(fn=llm_change, inputs=[model_mode], outputs=[llm]) fun_mode = gr.Radio(["试卷生成"], label="请选择功能模式", value="试卷生成") # fun_mode = gr.Radio(["试卷生成", "阅读理解生成", "作文批改"], label="请选择功能模式", value="试卷生成") pg = gr.Column(visible=True) qg = gr.Row(visible=False) aa = gr.Row(visible=False) fun_mode.change(fn=function_select, inputs=[fun_mode], outputs=[pg, qg, aa]) # progress.change(fn=llm_change, inputs=[model_mode], outputs=[llm]) with pg: progress = gr.Radio(['unit1', 'unit2', 'unit3', 'unit4', 'unit5', 'unit6', 'unit7', '期中', 'unit8', 'unit9', 'unit10', 'unit11', 'unit12', 'unit13', 'unit14', '期末'], label="请选择教学进度") with gr.Row(): with gr.Column(scale=10): gr.Markdown('\n\n\n\n') gr.Markdown('📚**************word pronunciation**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') word_p1 = gr.Slider(0, 5, value=2, step=1, label="选择划线部分发音不同的单词", interactive=True) word_p2 = gr.Slider(0, 5, value=1, step=1, label="选择与指定单词划线部分发音不同的单词", interactive=True) word_p3 = gr.Slider(0, 5, value=2, step=1, label="以下划线字母哪个发/r/的音", interactive=True) gr.Markdown('\n') gr.Markdown('judge') gr.Markdown('\n') word_p4 = gr.Slider(0, 5, value=1, step=1, label="判断下列单词划线部分读音是否相同", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************word spelling**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') word_s1 = gr.Slider(0, 5, value=2, step=1, label="选出拼写正确的单词", interactive=True) word_s2 = gr.Slider(0, 5, value=1, step=1, label="选择正确的拼写补全单词", interactive=True) word_s3 = gr.Slider(0, 5, value=2, step=1, label="看图,选出该图表示单词的首字母", interactive=True) gr.Markdown('\n') gr.Markdown('fill') gr.Markdown('\n') word_s4 = gr.Slider(0, 5, value=1, step=1, label="根据图片补全单词", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************word meaning**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') word_m1 = gr.Slider(0, 5, value=2, step=1, label="挑选一组词中不同类的词", interactive=True) word_m2 = gr.Slider(0, 5, value=1, step=1, label="挑选单词的正确释义", interactive=True) word_m3 = gr.Slider(0, 5, value=2, step=1, label="选择可以替换划线部分的词", interactive=True) word_m4 = gr.Slider(0, 5, value=2, step=1, label="选择与图片相符的单词", interactive=True) gr.Markdown('\n') gr.Markdown('judge') gr.Markdown('\n') word_m5 = gr.Slider(0, 5, value=1, step=1, label="判断单词中文意思是否正确", interactive=True) word_m6 = gr.Slider(0, 5, value=1, step=1, label="判断下列单词是否属于同一类", interactive=True) gr.Markdown('\n') gr.Markdown('fill') gr.Markdown('\n') word_m7 = gr.Slider(0, 5, value=1, step=1, label="根据汉语提示补全句子", interactive=True) word_m8 = gr.Slider(0, 5, value=1, step=1, label="根据图片提示补全句子", interactive=True) word_m9 = gr.Slider(0, 5, value=1, step=1, label="下厨下列单词的反义词", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************fixed phrase**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') phrase_f1 = gr.Slider(0, 5, value=2, step=1, label="请选择合适的词语将句子补充完整", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************sentence structure**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('fill') gr.Markdown('\n') sentence_s1 = gr.Slider(0, 5, value=2, step=1, label="请将下列单词组成句子", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************sentence meaning**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('fill') gr.Markdown('\n') sentence_s2 = gr.Slider(0, 5, value=2, step=1, label="请将下列汉语翻译成对应英语", interactive=True) gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') sentence_s3 = gr.Slider(0, 5, value=2, step=1, label="选出正确的中文翻译", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************名词所有格**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') grammar_1 = gr.Slider(0, 5, value=2, step=1, label="请选择正确的单词进行填空", interactive=True) gr.Markdown('\n\n\n\n') gr.Markdown('📚**************there be 句型**************📚') gr.Markdown('\n\n\n\n') gr.Markdown('\n') gr.Markdown('choice') gr.Markdown('\n') grammar_2 = gr.Slider(0, 5, value=2, step=1, label="请选择正确的单词进行填空", interactive=True) # gr.Markdown(f'试卷存储路径') # paper_path = gr.Textbox(show_label=False, placeholder="请输入待生成试卷存放路径", # value='.\\papers\\', lines=1).style(container=False) generate_button = gr.Button(value="生成试卷", visible=False) with gr.Column(scale=10): chatbot = gr.Chatbot([[None, None]], elem_id="chat-box", show_label=False).style(height=1000) generate_button.click(fn=generate_paper, inputs=[progress, word_p1, word_p2, word_p3, word_p4, word_s1, word_s2, word_s3, word_s4, word_m1, word_m2, word_m3, word_m4, word_m5, word_m6, word_m7, word_m8, word_m9, phrase_f1, sentence_s1, sentence_s2, sentence_s3, grammar_1, grammar_2], outputs=[chatbot]) with qg: with gr.Column(scale=10): chatbot = gr.Chatbot([[None, None]], elem_id="chat-box", show_label=False).style(height=800) clear_button = gr.Button(value="清屏") clear_button.click(fn=clear_screen, inputs=[chatbot], outputs=[chatbot]) with gr.Column(scale=10): with gr.Tab('生成配置'): generate_number = gr.Slider(1, 5, value=3, step=1, label="请设定单篇文章需要生成的问题数量", interactive=True) gr.Markdown(f'单篇生成') texts = gr.Textbox(show_label=False, placeholder="文本内容", lines=12).style(container=False) text_button = gr.Button(value="生成问题") text_button.click(fn=text_generate, inputs=[chatbot, texts, generate_number, llm], outputs=[chatbot]) gr.Markdown(f'批量生成') folder_address = gr.File(label="添加文件", file_types=['.txt', '.md', '.docx', '.pdf'], file_count="multiple", show_label=False ) file_button = gr.Button(value="生成问题") file_button.click(fn=files_generate, inputs=[chatbot, folder_address, generate_number, llm], outputs=[chatbot]) with aa: with gr.Column(scale=10): chatbot = gr.Chatbot([[None, None]], elem_id="chat-box", show_label=False).style(height=800) clear_button = gr.Button(value="清屏") clear_button.click(fn=clear_screen, inputs=[chatbot], outputs=[chatbot]) with gr.Column(scale=10): with gr.Tab('批改配置'): gr.Markdown(f'写作要求') require_texts = gr.Textbox(show_label=False, placeholder="文本内容", lines=4).style(container=False) # require_texts_button = gr.Button(value="批改") # require_texts_button.click(fn=text_correct, inputs=[chatbot, texts, llm], outputs=[chatbot]) gr.Markdown(f'单篇批改') feedback_texts = gr.Textbox(show_label=False, placeholder="文本内容", lines=12).style(container=False) feedback_button = gr.Button(value="批改") feedback_button.click(fn=text_correct, inputs=[chatbot, require_texts, feedback_texts, llm], outputs=[chatbot]) gr.Markdown(f'批量批改') folder_address = gr.File(label="添加文件", file_types=['.txt', '.md', '.docx', '.pdf'], file_count="multiple", show_label=False ) file_button = gr.Button(value="批改") file_button.click(fn=files_correct, inputs=[chatbot, require_texts, folder_address, llm], outputs=[chatbot]) demo.queue(concurrency_count=5).launch(server_name='0.0.0.0', server_port=7858, share=True)