youngtsai commited on
Commit
f35c083
·
1 Parent(s): 252a456

paragraph_refine_output = gr.Textbox(label="Refine Paragraph 段落改善建議")

Browse files
Files changed (1) hide show
  1. app.py +64 -1
app.py CHANGED
@@ -203,11 +203,12 @@ def generate_paragraph_evaluate(paragraph, user_generate_paragraph_evaluate_prom
203
 
204
  return content
205
 
206
- def generate_correct_grammatical_spelling_errors(paragraph, user_correct_grammatical_spelling_errors_prompt):
207
  """
208
  根据用户输入的段落,调用OpenAI API生成相关的文法和拼字错误修正。
209
  """
210
  user_content = f"""
 
211
  paragraph is {paragraph}
212
  {user_correct_grammatical_spelling_errors_prompt}
213
  """
@@ -230,6 +231,34 @@ def generate_correct_grammatical_spelling_errors(paragraph, user_correct_grammat
230
 
231
  return content
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  with gr.Blocks() as demo:
234
  with gr.Row():
235
  with gr.Column():
@@ -397,6 +426,29 @@ with gr.Blocks() as demo:
397
  user_correct_grammatical_spelling_errors_prompt = gr.Textbox(label="Correct Grammatical and Spelling Errors Prompt", value=default_user_correct_grammatical_spelling_errors_prompt)
398
  generate_correct_grammatical_spelling_errors_button = gr.Button("Correct Grammatical and Spelling Errors")
399
  correct_grammatical_spelling_errors_output = gr.Textbox(label="Correct Grammatical and Spelling Errors 修訂文法與拼字錯誤")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
401
  generate_topics_button.click(
402
  fn=generate_topics,
@@ -494,10 +546,21 @@ with gr.Blocks() as demo:
494
  generate_correct_grammatical_spelling_errors_button.click(
495
  fn=generate_correct_grammatical_spelling_errors,
496
  inputs=[
 
497
  paragraph_input,
498
  user_correct_grammatical_spelling_errors_prompt
499
  ],
500
  outputs=correct_grammatical_spelling_errors_output
501
  )
502
 
 
 
 
 
 
 
 
 
 
 
503
  demo.launch()
 
203
 
204
  return content
205
 
206
+ def generate_correct_grammatical_spelling_errors(eng_level, paragraph, user_correct_grammatical_spelling_errors_prompt):
207
  """
208
  根据用户输入的段落,调用OpenAI API生成相关的文法和拼字错误修正。
209
  """
210
  user_content = f"""
211
+ level is {eng_level}
212
  paragraph is {paragraph}
213
  {user_correct_grammatical_spelling_errors_prompt}
214
  """
 
231
 
232
  return content
233
 
234
+ def generate_refine_paragraph(eng_level, paragraph, user_refine_paragraph_prompt):
235
+ """
236
+ 根据用户输入的段落,调用OpenAI API生成相关的段落改善建议。
237
+ """
238
+ user_content = f"""
239
+ eng_level is {eng_level}
240
+ paragraph is {paragraph}
241
+ {user_refine_paragraph_prompt}
242
+ """
243
+ messages = [
244
+ {"role": "system", "content": paragraph},
245
+ {"role": "user", "content": user_content}
246
+ ]
247
+
248
+ response_format = { "type": "json_object" }
249
+
250
+ request_payload = {
251
+ "model": "gpt-3.5-turbo",
252
+ "messages": messages,
253
+ "max_tokens": 500,
254
+ "response_format": response_format
255
+ }
256
+
257
+ response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
258
+ content = response.choices[0].message.content
259
+
260
+ return content
261
+
262
  with gr.Blocks() as demo:
263
  with gr.Row():
264
  with gr.Column():
 
426
  user_correct_grammatical_spelling_errors_prompt = gr.Textbox(label="Correct Grammatical and Spelling Errors Prompt", value=default_user_correct_grammatical_spelling_errors_prompt)
427
  generate_correct_grammatical_spelling_errors_button = gr.Button("Correct Grammatical and Spelling Errors")
428
  correct_grammatical_spelling_errors_output = gr.Textbox(label="Correct Grammatical and Spelling Errors 修訂文法與拼字錯誤")
429
+ paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="Paragraph")
430
+
431
+ gr.Markdown("## 10. Refine Paragraph 段落改善建議")
432
+ default_user_refine_paragraph_prompt = """
433
+ I need assistance with revising a paragraph. Please "Refine" the "Revised Version 1" and immediately "Provide Explanations" for each suggestion you made.
434
+ - Revised Version 1 (for correction): paragraph_ai_modification(split by 標點符號)
435
+ - Do not modify the sentence: topicSentence"
436
+ - Make sure any revised vocabulary aligns with the level.
437
+ - Guidelines for Length and Complexity:
438
+ Please keep explanations concise and straightforward,
439
+ avoiding overly technical language.
440
+ The response should strictly be in the below JSON format and nothing else:
441
+ {
442
+ "Suggestions and Explanations": [
443
+ { "Origin": "#original_text_1", "Suggestion": "#suggestion_1", "Explanation": "#explanation_1" },
444
+ { "Origin": "#original_text_2", "Suggestion": "#suggestion_2", "Explanation": "#explanation_2" },
445
+ ... ],
446
+ "Revised Paragraph": "#revised_paragraph_v2"
447
+ }
448
+ """
449
+ user_refine_paragraph_prompt = gr.Textbox(label="Refine Paragraph Prompt", value=default_user_refine_paragraph_prompt)
450
+ generate_refine_paragraph_button = gr.Button("Refine Paragraph")
451
+ paragraph_refine_output = gr.Textbox(label="Refine Paragraph 段落改善建議")
452
 
453
  generate_topics_button.click(
454
  fn=generate_topics,
 
546
  generate_correct_grammatical_spelling_errors_button.click(
547
  fn=generate_correct_grammatical_spelling_errors,
548
  inputs=[
549
+ eng_level_input,
550
  paragraph_input,
551
  user_correct_grammatical_spelling_errors_prompt
552
  ],
553
  outputs=correct_grammatical_spelling_errors_output
554
  )
555
 
556
+ generate_refine_paragraph_button.click(
557
+ fn=generate_refine_paragraph,
558
+ inputs=[
559
+ eng_level_input,
560
+ paragraph_correct_grammatical_spelling_errors_input,
561
+ user_refine_paragraph_prompt
562
+ ],
563
+ outputs=paragraph_refine_output
564
+ )
565
+
566
  demo.launch()