Spaces:
Sleeping
Sleeping
def generate_refine_paragraph(model, max_tokens, sys_content, eng_level, paragraph):
Browse files
app.py
CHANGED
@@ -920,10 +920,39 @@ def highlight_diff_texts(highlight_list, text):
|
|
920 |
def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
|
921 |
return paragraph
|
922 |
|
923 |
-
def generate_refine_paragraph(model, sys_content, eng_level, paragraph
|
924 |
"""
|
925 |
根据用户输入的段落,调用 LLM API 生成相关的段落改善建議。
|
926 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
927 |
try:
|
928 |
user_content = f"""
|
929 |
eng_level is: {eng_level}
|
@@ -951,7 +980,7 @@ def generate_refine_paragraph(model, sys_content, eng_level, paragraph, user_ref
|
|
951 |
prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
|
952 |
messages=messages,
|
953 |
model=model,
|
954 |
-
max_tokens=
|
955 |
response_format={"type": "json_object"}
|
956 |
)
|
957 |
|
@@ -3006,37 +3035,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3006 |
# 段落改善建議
|
3007 |
with gr.Row():
|
3008 |
with gr.Column():
|
3009 |
-
with gr.Row() as paragraph_refine_params:
|
3010 |
-
default_user_refine_paragraph_prompt = """
|
3011 |
-
I need assistance with revising a paragraph. Please Refine the paragraph and immediately "Provide Explanations" for each suggestion you made.
|
3012 |
-
|
3013 |
-
Rules:
|
3014 |
-
- Do not modify the sentence: topicSentence"
|
3015 |
-
- Make sure any revised vocabulary aligns with the eng_level.
|
3016 |
-
- When explaining, use Traditional Chinese (Taiwan, 繁體中文 zh-TW) for clarity.
|
3017 |
-
- But others(Origin, Suggestion, revised_paragraph_v2) use English, that's very important.
|
3018 |
-
|
3019 |
-
Guidelines for Length and Complexity:
|
3020 |
-
- Please keep explanations concise and straightforward
|
3021 |
-
- if there are no problems, don't need to revise either no more suggestions to show in the revised paragraph.
|
3022 |
-
|
3023 |
-
Restrictions:
|
3024 |
-
- avoiding overly technical language.
|
3025 |
-
- don't change the text's case in the original text.
|
3026 |
-
|
3027 |
-
The response should strictly be in the below JSON format and nothing else:
|
3028 |
-
|
3029 |
-
EXAMPLE:
|
3030 |
-
{
|
3031 |
-
"Suggestions and Explanations": [
|
3032 |
-
{ "origin": "#original_text_1", "suggestion": "#suggestion_1", "explanation": "#explanation_1(in_traditional_chinese zh-TW)" },
|
3033 |
-
{ "origin": "#original_text_2", "suggestion": "#suggestion_2", "explanation": "#explanation_2(in_traditional_chinese zh-TW)" },
|
3034 |
-
... ],
|
3035 |
-
"Revised Paragraph": "#revised_paragraph_v2"
|
3036 |
-
}
|
3037 |
-
"""
|
3038 |
-
user_refine_paragraph_prompt = gr.Textbox(label="Refine Paragraph Prompt", value=default_user_refine_paragraph_prompt, visible=False)
|
3039 |
-
|
3040 |
with gr.Row() as paragraph_refine_html:
|
3041 |
gr.Markdown("# Step 8. 段落改善建議")
|
3042 |
with gr.Accordion("📝 參考指引:段落改善建議?", open=False ):
|
@@ -3111,10 +3109,10 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3111 |
fn=generate_refine_paragraph,
|
3112 |
inputs=[
|
3113 |
model,
|
|
|
3114 |
sys_content_input,
|
3115 |
eng_level_input,
|
3116 |
paragraph_correct_grammatical_spelling_errors_input,
|
3117 |
-
user_refine_paragraph_prompt
|
3118 |
],
|
3119 |
outputs=[refine_output_table, refine_output]
|
3120 |
).then(
|
@@ -3345,11 +3343,11 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3345 |
generate_full_paragraph_refine_button.click(
|
3346 |
fn=generate_refine_paragraph,
|
3347 |
inputs=[
|
3348 |
-
model,
|
|
|
3349 |
sys_content_input,
|
3350 |
eng_level_input,
|
3351 |
full_paragraph_refine_input,
|
3352 |
-
user_refine_paragraph_prompt
|
3353 |
],
|
3354 |
outputs=[full_paragraph_refine_output_table, full_paragraph_refine_output]
|
3355 |
).then(
|
@@ -3465,9 +3463,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3465 |
with gr.Column():
|
3466 |
past_exam_refine_input = gr.TextArea(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:", show_copy_button=True)
|
3467 |
with gr.Column():
|
3468 |
-
with gr.Row():
|
3469 |
-
with gr.Accordion("prompt 提供微調測試", open=False, elem_classes=['accordion-prompts'], visible=False):
|
3470 |
-
past_exam_refine_paragraph_prompt = gr.Textbox(label="Refine Paragraph Prompt", value=default_user_refine_paragraph_prompt, lines= 20)
|
3471 |
with gr.Row():
|
3472 |
past_exam_generate_refine_button = gr.Button("段落改善建議", variant="primary")
|
3473 |
with gr.Row():
|
@@ -3597,7 +3592,13 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3597 |
|
3598 |
past_exam_generate_refine_button.click(
|
3599 |
fn=generate_refine_paragraph,
|
3600 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
3601 |
outputs=[past_exam_refine_output_table, past_exam_refine_output]
|
3602 |
).then(
|
3603 |
fn=highlight_diff_texts,
|
|
|
920 |
def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
|
921 |
return paragraph
|
922 |
|
923 |
+
def generate_refine_paragraph(model, max_tokens, sys_content, eng_level, paragraph):
|
924 |
"""
|
925 |
根据用户输入的段落,调用 LLM API 生成相关的段落改善建議。
|
926 |
"""
|
927 |
+
user_refine_paragraph_prompt = """
|
928 |
+
I need assistance with revising a paragraph. Please Refine the paragraph and immediately "Provide Explanations" for each suggestion you made.
|
929 |
+
|
930 |
+
Rules:
|
931 |
+
- Do not modify the sentence: topicSentence"
|
932 |
+
- Make sure any revised vocabulary aligns with the eng_level.
|
933 |
+
- When explaining, use Traditional Chinese (Taiwan, 繁體中文 zh-TW) for clarity.
|
934 |
+
- But others(Origin, Suggestion, revised_paragraph_v2) use English, that's very important.
|
935 |
+
|
936 |
+
Guidelines for Length and Complexity:
|
937 |
+
- Please keep explanations concise and straightforward
|
938 |
+
- if there are no problems, don't need to revise either no more suggestions to show in the revised paragraph.
|
939 |
+
|
940 |
+
Restrictions:
|
941 |
+
- avoiding overly technical language.
|
942 |
+
- don't change the text's case in the original text.
|
943 |
+
|
944 |
+
The response should strictly be in the below JSON format and nothing else:
|
945 |
+
|
946 |
+
EXAMPLE:
|
947 |
+
{
|
948 |
+
"Suggestions and Explanations": [
|
949 |
+
{ "origin": "#original_text_1", "suggestion": "#suggestion_1", "explanation": "#explanation_1(in_traditional_chinese zh-TW)" },
|
950 |
+
{ "origin": "#original_text_2", "suggestion": "#suggestion_2", "explanation": "#explanation_2(in_traditional_chinese zh-TW)" },
|
951 |
+
... ],
|
952 |
+
"Revised Paragraph": "#revised_paragraph_v2"
|
953 |
+
}
|
954 |
+
"""
|
955 |
+
|
956 |
try:
|
957 |
user_content = f"""
|
958 |
eng_level is: {eng_level}
|
|
|
980 |
prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
|
981 |
messages=messages,
|
982 |
model=model,
|
983 |
+
max_tokens=max_tokens,
|
984 |
response_format={"type": "json_object"}
|
985 |
)
|
986 |
|
|
|
3035 |
# 段落改善建議
|
3036 |
with gr.Row():
|
3037 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3038 |
with gr.Row() as paragraph_refine_html:
|
3039 |
gr.Markdown("# Step 8. 段落改善建議")
|
3040 |
with gr.Accordion("📝 參考指引:段落改善建議?", open=False ):
|
|
|
3109 |
fn=generate_refine_paragraph,
|
3110 |
inputs=[
|
3111 |
model,
|
3112 |
+
max_tokens,
|
3113 |
sys_content_input,
|
3114 |
eng_level_input,
|
3115 |
paragraph_correct_grammatical_spelling_errors_input,
|
|
|
3116 |
],
|
3117 |
outputs=[refine_output_table, refine_output]
|
3118 |
).then(
|
|
|
3343 |
generate_full_paragraph_refine_button.click(
|
3344 |
fn=generate_refine_paragraph,
|
3345 |
inputs=[
|
3346 |
+
model,
|
3347 |
+
max_tokens,
|
3348 |
sys_content_input,
|
3349 |
eng_level_input,
|
3350 |
full_paragraph_refine_input,
|
|
|
3351 |
],
|
3352 |
outputs=[full_paragraph_refine_output_table, full_paragraph_refine_output]
|
3353 |
).then(
|
|
|
3463 |
with gr.Column():
|
3464 |
past_exam_refine_input = gr.TextArea(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:", show_copy_button=True)
|
3465 |
with gr.Column():
|
|
|
|
|
|
|
3466 |
with gr.Row():
|
3467 |
past_exam_generate_refine_button = gr.Button("段落改善建議", variant="primary")
|
3468 |
with gr.Row():
|
|
|
3592 |
|
3593 |
past_exam_generate_refine_button.click(
|
3594 |
fn=generate_refine_paragraph,
|
3595 |
+
inputs=[
|
3596 |
+
model,
|
3597 |
+
max_tokens,
|
3598 |
+
past_exam_evaluation_sys_content_prompt,
|
3599 |
+
eng_level_input,
|
3600 |
+
past_exam_refine_input,
|
3601 |
+
],
|
3602 |
outputs=[past_exam_refine_output_table, past_exam_refine_output]
|
3603 |
).then(
|
3604 |
fn=highlight_diff_texts,
|