weiwei1392 commited on
Commit
3623cb1
·
1 Parent(s): 82ffe6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -21
app.py CHANGED
@@ -18,10 +18,12 @@ generate_prompt = 'please generate {generate_number} difficult multiple-choice q
18
  'question according the paragraph below. Each question should have four choices and only one of them ' \
19
  'is the right answer.' \
20
 
21
- correct_prompt = 'the following paragraph is a composition of a student. ' \
22
- 'please first judge the writing level of the composition, ' \
23
- 'then point out the all the problems with examples, ' \
24
- 'and finally output the complete revised version.'
 
 
25
 
26
  llm_name_dict = {'chatgpt-3.5': 'OpenAI3', 'chatgpt-4': 'OpenAI4', 'chatglm—6b': 'ChatGLM'}
27
 
@@ -50,7 +52,7 @@ def llm_change(name):
50
 
51
 
52
  def text_generate(chatbot, text, generate_number, llm):
53
- prompt = eval('f"' + generate_prompt + '"') + '\n\n' + text
54
  answer = llm(prompt)
55
  chatbot = chatbot + [[text, answer]]
56
  return chatbot
@@ -60,7 +62,7 @@ def files_generate(chatbot, files_list, generate_number, llm):
60
  try:
61
  texts = files_list_to_texts(files_list)
62
  for text in texts:
63
- prompt = eval('f"' + generate_prompt + '"') + '\n\n' + text
64
  answer = llm(prompt)
65
  chatbot = chatbot + [[text, answer]]
66
  except:
@@ -68,20 +70,23 @@ def files_generate(chatbot, files_list, generate_number, llm):
68
  return chatbot
69
 
70
 
71
- def text_correct(chatbot, text, llm):
72
- prompt = correct_prompt + '\n\n' + text
73
- answer = llm(prompt)
74
- chatbot = chatbot + [[text, answer]]
 
 
75
  return chatbot
76
 
77
 
78
- def files_correct(chatbot, files_list, llm):
 
79
  try:
80
- texts = files_list_to_texts(files_list)
81
- for text in texts:
82
- prompt = correct_prompt + '\n\n' + text
83
- answer = llm(prompt)
84
- chatbot = chatbot + [[text, answer]]
85
  except:
86
  chatbot = chatbot + [[None, f"所选文件夹中的文件添加失败,请确保文件夹中含有txt类型文件"]]
87
  return chatbot
@@ -154,10 +159,16 @@ with gr.Blocks(css=block_css) as demo:
154
 
155
  with gr.Tab('批改配置'):
156
 
 
 
 
 
 
157
  gr.Markdown(f'单篇批改')
158
- texts = gr.Textbox(show_label=False, placeholder="文本内容", lines=16).style(container=False)
159
- text_button = gr.Button(value="批改")
160
- text_button.click(fn=text_correct, inputs=[chatbot, texts, llm], outputs=[chatbot])
 
161
 
162
  gr.Markdown(f'批量批改')
163
  folder_address = gr.File(label="添加文件",
@@ -166,7 +177,8 @@ with gr.Blocks(css=block_css) as demo:
166
  show_label=False
167
  )
168
  file_button = gr.Button(value="批改")
169
- file_button.click(fn=files_correct, inputs=[chatbot, folder_address, llm], outputs=[chatbot])
 
170
 
171
 
172
- demo.queue(concurrency_count=5).launch()
 
18
  'question according the paragraph below. Each question should have four choices and only one of them ' \
19
  'is the right answer.' \
20
 
21
+ # correct_prompt = 'the following paragraph is a composition of a student. ' \
22
+ # 'please first judge the writing level of the composition, ' \
23
+ # 'then point out the all the problems with examples, ' \
24
+ # 'and finally output the complete revised version.'
25
+
26
+ correct_prompt = '你是一个英语老师,现在正在批改学生的英语作文。你会用中文说明并逐一标记出每个英语语法错误,并且说明如何改正;最后,给出完整的正确作文。'
27
 
28
  llm_name_dict = {'chatgpt-3.5': 'OpenAI3', 'chatgpt-4': 'OpenAI4', 'chatglm—6b': 'ChatGLM'}
29
 
 
52
 
53
 
54
  def text_generate(chatbot, text, generate_number, llm):
55
+ prompt = eval('f"' + generate_prompt + '"') + '\n\nstop\n\n' + text
56
  answer = llm(prompt)
57
  chatbot = chatbot + [[text, answer]]
58
  return chatbot
 
62
  try:
63
  texts = files_list_to_texts(files_list)
64
  for text in texts:
65
+ prompt = eval('f"' + generate_prompt + '"') + '\n\nstop\n\n' + text
66
  answer = llm(prompt)
67
  chatbot = chatbot + [[text, answer]]
68
  except:
 
70
  return chatbot
71
 
72
 
73
+ def text_correct(chatbot, require_texts, feedback_texts, llm):
74
+ req = '写作要求为:\n' + require_texts
75
+ answer = '学生的作文内容为:\n' + feedback_texts
76
+ prompt = correct_prompt + req + '\n\nstop\n\n' + answer
77
+ response = llm(prompt)
78
+ chatbot = chatbot + [[answer, response]]
79
  return chatbot
80
 
81
 
82
+ def files_correct(chatbot, require_texts, files_list, llm):
83
+ req = '写作要求为:\n' + require_texts
84
  try:
85
+ answers = files_list_to_texts(files_list)
86
+ for answer in answers:
87
+ prompt = correct_prompt + req + '\n\nstop\n\n' + '学生的作文内容为:\n' + answer
88
+ response = llm(prompt)
89
+ chatbot = chatbot + [['学生的作文内容为:\n' + answer, response]]
90
  except:
91
  chatbot = chatbot + [[None, f"所选文件夹中的文件添加失败,请确保文件夹中含有txt类型文件"]]
92
  return chatbot
 
159
 
160
  with gr.Tab('批改配置'):
161
 
162
+ gr.Markdown(f'写作要求')
163
+ require_texts = gr.Textbox(show_label=False, placeholder="文本内容", lines=4).style(container=False)
164
+ # require_texts_button = gr.Button(value="批改")
165
+ # require_texts_button.click(fn=text_correct, inputs=[chatbot, texts, llm], outputs=[chatbot])
166
+
167
  gr.Markdown(f'单篇批改')
168
+ feedback_texts = gr.Textbox(show_label=False, placeholder="文本内容", lines=12).style(container=False)
169
+ feedback_button = gr.Button(value="批改")
170
+ feedback_button.click(fn=text_correct, inputs=[chatbot, require_texts, feedback_texts, llm],
171
+ outputs=[chatbot])
172
 
173
  gr.Markdown(f'批量批改')
174
  folder_address = gr.File(label="添加文件",
 
177
  show_label=False
178
  )
179
  file_button = gr.Button(value="批改")
180
+ file_button.click(fn=files_correct, inputs=[chatbot, require_texts, folder_address, llm],
181
+ outputs=[chatbot])
182
 
183
 
184
+ demo.queue(concurrency_count=5).launch(share=True)