Spaces:
Sleeping
Sleeping
def generate_correct_grammatical_spelling_errors(model, max_tokens, sys_content, eng_level, paragraph):
Browse files
app.py
CHANGED
@@ -767,10 +767,48 @@ def generate_paragraph_evaluate(model, max_tokens, sys_content, paragraph):
|
|
767 |
error_msg = handle_evaluation_error(e)
|
768 |
raise gr.Error(error_msg)
|
769 |
|
770 |
-
def generate_correct_grammatical_spelling_errors(model, sys_content, eng_level, paragraph
|
771 |
"""
|
772 |
根據用戶輸入的段落,生成文法和拼字錯誤修正建議。
|
773 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
774 |
try:
|
775 |
user_content = f"""
|
776 |
level is: {eng_level}
|
@@ -798,7 +836,7 @@ def generate_correct_grammatical_spelling_errors(model, sys_content, eng_level,
|
|
798 |
prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
|
799 |
messages=messages,
|
800 |
model=model,
|
801 |
-
max_tokens=
|
802 |
response_format={"type": "json_object"}
|
803 |
)
|
804 |
|
@@ -2947,47 +2985,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
2947 |
|
2948 |
# 修訂文法與拼字錯誤
|
2949 |
with gr.Row():
|
2950 |
-
with gr.Column():
|
2951 |
-
with gr.Row() as paragraph_correct_grammatical_spelling_errors_params:
|
2952 |
-
default_user_correct_grammatical_spelling_errors_prompt = """
|
2953 |
-
I'm aiming to improve my writing.
|
2954 |
-
Please assist me by "Correcting Grammatical and Spelling Errors" in the provided paragraph.
|
2955 |
-
For every correction you make, I'd like an "Explanation" to understand the reasoning behind it.
|
2956 |
-
|
2957 |
-
Rules:
|
2958 |
-
- Paragraph for Correction: [paragraph split by punctuation mark]
|
2959 |
-
- The sentence to remain unchanged: [sentence_to_remain_unchanged]
|
2960 |
-
- When explaining, use Traditional Chinese (Taiwan, 繁體中文) for clarity.
|
2961 |
-
- But others(original, Correction, revised_paragraph) in English.
|
2962 |
-
- Make sure any revised vocabulary aligns with the eng_level.
|
2963 |
-
- Prepositions Followed by Gerunds: After a preposition, a gerund (the -ing form of a verb) should be used. For example: "interested in reading."
|
2964 |
-
- Two Main Verbs in a Sentence: When a sentence has two main verbs, it is necessary to use conjunctions, infinitives, clauses, or participles to correctly organize and connect the verbs, avoiding confusion in the sentence structure.
|
2965 |
-
|
2966 |
-
Guidelines for Length and Complexity:
|
2967 |
-
- Please keep explanations concise and straightforward
|
2968 |
-
- if there are no grammatical or spelling errors, don't need to revise either no more suggestions to show in the revised paragraph.
|
2969 |
-
|
2970 |
-
Restrictions:
|
2971 |
-
- avoiding overly technical language.
|
2972 |
-
- don't give any suggestions about the sentence to remain unchanged.
|
2973 |
-
- don't give suggestions about the Period, Comma etc.
|
2974 |
-
- Do not change the original text's case.
|
2975 |
-
- if no mistakes, don't need to revise.
|
2976 |
-
|
2977 |
-
The response should strictly be in the below JSON format and nothing else:
|
2978 |
-
|
2979 |
-
EXAMPLE:
|
2980 |
-
{{
|
2981 |
-
"Corrections and Explanations": [
|
2982 |
-
{{ "original": "# original_sentence1", "correction": "#correction_1", "explanation": "#explanation_1(in_traditional_chinese ZH-TW)" }},
|
2983 |
-
{{ "original": "# original_sentence2", "correction": "#correction_2", "explanation": "#explanation_2(in_traditional_chinese ZH-TW)" }},
|
2984 |
-
...
|
2985 |
-
],
|
2986 |
-
"Revised Paragraph": "#revised_paragraph"
|
2987 |
-
}}
|
2988 |
-
"""
|
2989 |
-
user_correct_grammatical_spelling_errors_prompt = gr.Textbox(label="Correct Grammatical and Spelling Errors Prompt", value=default_user_correct_grammatical_spelling_errors_prompt, visible=False)
|
2990 |
-
|
2991 |
with gr.Row() as paragraph_correct_grammatical_spelling_errors_html:
|
2992 |
gr.Markdown("# Step 7. 修訂文法與拼字錯誤")
|
2993 |
with gr.Accordion("📝 參考指引:AI 的混淆狀況?", open=False):
|
@@ -3085,10 +3083,10 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3085 |
fn=generate_correct_grammatical_spelling_errors,
|
3086 |
inputs=[
|
3087 |
model,
|
|
|
3088 |
sys_content_input,
|
3089 |
eng_level_input,
|
3090 |
paragraph_output,
|
3091 |
-
user_correct_grammatical_spelling_errors_prompt,
|
3092 |
],
|
3093 |
outputs=[
|
3094 |
correct_grammatical_spelling_errors_output_table,
|
@@ -3326,7 +3324,13 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3326 |
|
3327 |
generate_full_paragraph_correct_grammatical_spelling_errors_button.click(
|
3328 |
fn=generate_correct_grammatical_spelling_errors,
|
3329 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
3330 |
outputs=[full_paragraph_correct_grammatical_spelling_errors_output_table, revised_full_paragraph_output]
|
3331 |
).then(
|
3332 |
fn=highlight_diff_texts,
|
@@ -3445,9 +3449,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3445 |
with gr.Column():
|
3446 |
past_exam_correct_grammatical_spelling_errors_input = gr.TextArea(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:",lines= 10, show_copy_button=True)
|
3447 |
with gr.Column():
|
3448 |
-
with gr.Row():
|
3449 |
-
with gr.Accordion("prompt 提供微調測試", open=False, elem_classes=['accordion-prompts'], visible=False):
|
3450 |
-
past_exam_correct_grammatical_spelling_errors_prompt = gr.Textbox(label="Correct Grammatical and Spelling Errors Prompt", value=default_user_correct_grammatical_spelling_errors_prompt, lines= 20)
|
3451 |
with gr.Row():
|
3452 |
past_exam_generate_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
|
3453 |
with gr.Row():
|
@@ -3576,7 +3577,13 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3576 |
|
3577 |
past_exam_generate_correct_grammatical_spelling_errors_button.click(
|
3578 |
fn=generate_correct_grammatical_spelling_errors,
|
3579 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
3580 |
outputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output]
|
3581 |
).then(
|
3582 |
fn=highlight_diff_texts,
|
|
|
767 |
error_msg = handle_evaluation_error(e)
|
768 |
raise gr.Error(error_msg)
|
769 |
|
770 |
+
def generate_correct_grammatical_spelling_errors(model, max_tokens, sys_content, eng_level, paragraph):
|
771 |
"""
|
772 |
根據用戶輸入的段落,生成文法和拼字錯誤修正建議。
|
773 |
"""
|
774 |
+
user_correct_grammatical_spelling_errors_prompt = """
|
775 |
+
I'm aiming to improve my writing.
|
776 |
+
Please assist me by "Correcting Grammatical and Spelling Errors" in the provided paragraph.
|
777 |
+
For every correction you make, I'd like an "Explanation" to understand the reasoning behind it.
|
778 |
+
|
779 |
+
Rules:
|
780 |
+
- Paragraph for Correction: [paragraph split by punctuation mark]
|
781 |
+
- The sentence to remain unchanged: [sentence_to_remain_unchanged]
|
782 |
+
- When explaining, use Traditional Chinese (Taiwan, 繁體中文) for clarity.
|
783 |
+
- But others(original, Correction, revised_paragraph) in English.
|
784 |
+
- Make sure any revised vocabulary aligns with the eng_level.
|
785 |
+
- Prepositions Followed by Gerunds: After a preposition, a gerund (the -ing form of a verb) should be used. For example: "interested in reading."
|
786 |
+
- Two Main Verbs in a Sentence: When a sentence has two main verbs, it is necessary to use conjunctions, infinitives, clauses, or participles to correctly organize and connect the verbs, avoiding confusion in the sentence structure.
|
787 |
+
|
788 |
+
Guidelines for Length and Complexity:
|
789 |
+
- Please keep explanations concise and straightforward
|
790 |
+
- if there are no grammatical or spelling errors, don't need to revise either no more suggestions to show in the revised paragraph.
|
791 |
+
|
792 |
+
Restrictions:
|
793 |
+
- avoiding overly technical language.
|
794 |
+
- don't give any suggestions about the sentence to remain unchanged.
|
795 |
+
- don't give suggestions about the Period, Comma etc.
|
796 |
+
- Do not change the original text's case.
|
797 |
+
- if no mistakes, don't need to revise.
|
798 |
+
|
799 |
+
The response should strictly be in the below JSON format and nothing else:
|
800 |
+
|
801 |
+
EXAMPLE:
|
802 |
+
{{
|
803 |
+
"Corrections and Explanations": [
|
804 |
+
{{ "original": "# original_sentence1", "correction": "#correction_1", "explanation": "#explanation_1(in_traditional_chinese ZH-TW)" }},
|
805 |
+
{{ "original": "# original_sentence2", "correction": "#correction_2", "explanation": "#explanation_2(in_traditional_chinese ZH-TW)" }},
|
806 |
+
...
|
807 |
+
],
|
808 |
+
"Revised Paragraph": "#revised_paragraph"
|
809 |
+
}}
|
810 |
+
"""
|
811 |
+
|
812 |
try:
|
813 |
user_content = f"""
|
814 |
level is: {eng_level}
|
|
|
836 |
prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
|
837 |
messages=messages,
|
838 |
model=model,
|
839 |
+
max_tokens=max_tokens,
|
840 |
response_format={"type": "json_object"}
|
841 |
)
|
842 |
|
|
|
2985 |
|
2986 |
# 修訂文法與拼字錯誤
|
2987 |
with gr.Row():
|
2988 |
+
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2989 |
with gr.Row() as paragraph_correct_grammatical_spelling_errors_html:
|
2990 |
gr.Markdown("# Step 7. 修訂文法與拼字錯誤")
|
2991 |
with gr.Accordion("📝 參考指引:AI 的混淆狀況?", open=False):
|
|
|
3083 |
fn=generate_correct_grammatical_spelling_errors,
|
3084 |
inputs=[
|
3085 |
model,
|
3086 |
+
max_tokens,
|
3087 |
sys_content_input,
|
3088 |
eng_level_input,
|
3089 |
paragraph_output,
|
|
|
3090 |
],
|
3091 |
outputs=[
|
3092 |
correct_grammatical_spelling_errors_output_table,
|
|
|
3324 |
|
3325 |
generate_full_paragraph_correct_grammatical_spelling_errors_button.click(
|
3326 |
fn=generate_correct_grammatical_spelling_errors,
|
3327 |
+
inputs=[
|
3328 |
+
model,
|
3329 |
+
max_tokens,
|
3330 |
+
sys_content_input,
|
3331 |
+
eng_level_input,
|
3332 |
+
full_paragraph_correct_grammatical_spelling_errors_input,
|
3333 |
+
],
|
3334 |
outputs=[full_paragraph_correct_grammatical_spelling_errors_output_table, revised_full_paragraph_output]
|
3335 |
).then(
|
3336 |
fn=highlight_diff_texts,
|
|
|
3449 |
with gr.Column():
|
3450 |
past_exam_correct_grammatical_spelling_errors_input = gr.TextArea(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:",lines= 10, show_copy_button=True)
|
3451 |
with gr.Column():
|
|
|
|
|
|
|
3452 |
with gr.Row():
|
3453 |
past_exam_generate_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
|
3454 |
with gr.Row():
|
|
|
3577 |
|
3578 |
past_exam_generate_correct_grammatical_spelling_errors_button.click(
|
3579 |
fn=generate_correct_grammatical_spelling_errors,
|
3580 |
+
inputs=[
|
3581 |
+
model,
|
3582 |
+
max_tokens,
|
3583 |
+
past_exam_evaluation_sys_content_prompt,
|
3584 |
+
eng_level_input,
|
3585 |
+
past_exam_correct_grammatical_spelling_errors_input,
|
3586 |
+
],
|
3587 |
outputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output]
|
3588 |
).then(
|
3589 |
fn=highlight_diff_texts,
|