youngtsai commited on
Commit
19c63ff
·
1 Parent(s): c1ee647

outputs=correct_grammatical_spelling_errors_output

Browse files
Files changed (2) hide show
  1. app.py +61 -0
  2. xx.js +0 -0
app.py CHANGED
@@ -203,6 +203,33 @@ def generate_paragraph_evaluate(paragraph, user_generate_paragraph_evaluate_prom
203
 
204
  return content
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  with gr.Blocks() as demo:
207
  with gr.Row():
208
  with gr.Column():
@@ -346,6 +373,31 @@ with gr.Blocks() as demo:
346
  generate_paragraph_evaluate_button = gr.Button("Save and Evaluate")
347
  paragraph_evaluate_output = gr.Textbox(label="Generated Paragraph evaluate 完整段落分析")
348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  generate_topics_button.click(
350
  fn=generate_topics,
351
  inputs=[
@@ -439,4 +491,13 @@ with gr.Blocks() as demo:
439
  outputs=paragraph_evaluate_output
440
  )
441
 
 
 
 
 
 
 
 
 
 
442
  demo.launch()
 
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
+ """
214
+ messages = [
215
+ {"role": "system", "content": paragraph},
216
+ {"role": "user", "content": user_content}
217
+ ]
218
+
219
+ response_format = { "type": "json_object" }
220
+
221
+ request_payload = {
222
+ "model": "gpt-3.5-turbo",
223
+ "messages": messages,
224
+ "max_tokens": 500,
225
+ "response_format": response_format
226
+ }
227
+
228
+ response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
229
+ content = response.choices[0].message.content
230
+
231
+ return content
232
+
233
  with gr.Blocks() as demo:
234
  with gr.Row():
235
  with gr.Column():
 
373
  generate_paragraph_evaluate_button = gr.Button("Save and Evaluate")
374
  paragraph_evaluate_output = gr.Textbox(label="Generated Paragraph evaluate 完整段落分析")
375
 
376
+ gr.Markdown("## 9. Correct Grammatical and Spelling Errors 修訂文法與拼字錯誤")
377
+ default_user_correct_grammatical_spelling_errors_prompt = """
378
+ I'm aiming to improve my writing.
379
+ Please assist me by "Correcting Grammatical and Spelling Errors" in the provided paragraph.
380
+ For every correction you make, I'd like an "Explanation" to understand the reasoning behind it.
381
+ - Paragraph for Correction: [paragraph_ai_modification(split by 標點符號)]
382
+ - The sentence to remain unchanged: [sentence_to_remain_unchanged]
383
+ - When explaining, use Traditional Chinese (Taiwan, 繁體中文) for clarity.
384
+ - Make sure any revised vocabulary aligns with the eng level.
385
+ - Guidelines for Length and Complexity: Please keep explanations concise and straightforward,
386
+ avoiding overly technical language.
387
+ The response should strictly be in the below JSON format and nothing else:
388
+ {
389
+ "Corrections and Explanations": [
390
+ { "original": "# original_sentence1", "Correction": "#correction_1", "Explanation": "#explanation_1_in_traditional_chinese" },
391
+ { "original": "# original_sentence2", "Correction": "#correction_2", "Explanation": "#explanation_2_in_traditional_chinese" },
392
+ ...
393
+ ],
394
+ "Revised Paragraph": "#revised_paragraph"
395
+ }
396
+ """
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,
403
  inputs=[
 
491
  outputs=paragraph_evaluate_output
492
  )
493
 
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()
xx.js ADDED
File without changes