Spaces:
Runtime error
Runtime error
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() | |