paper_generate / app.py
weiwei1392
none
2582aff
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()