Spaces:
Sleeping
Sleeping
def get_chinese_paragraph_refine_evaluate_content(model, sys_content, paragraph_1, paragraph_2, user_refine_paragraph_prompt):
Browse files
app.py
CHANGED
@@ -1123,17 +1123,7 @@ def assign_grade(subject_content, structure, diction, spelling_punctuation):
|
|
1123 |
# 預設為 🟡
|
1124 |
return "🟡"
|
1125 |
|
1126 |
-
def get_chinese_paragraph_evaluate_content(model,
|
1127 |
-
verify_string_length(paragraph)
|
1128 |
-
verify_moderation(paragraph)
|
1129 |
-
|
1130 |
-
user_content = f"""
|
1131 |
-
sys_content: {sys_content}
|
1132 |
-
---
|
1133 |
-
paragraph is: {paragraph}
|
1134 |
-
---
|
1135 |
-
{user_generate_paragraph_evaluate_prompt}
|
1136 |
-
"""
|
1137 |
content = generate_content_by_open_ai_assistant(user_content, thread_id=None, model_name=model)
|
1138 |
print(f"====generate_paragraph_evaluate====")
|
1139 |
print(content)
|
@@ -1152,8 +1142,7 @@ def get_chinese_paragraph_evaluate_content(model, sys_content, paragraph, user_g
|
|
1152 |
["遣詞造句", data['遣詞造句']['level'], data['遣詞造句']['explanation']],
|
1153 |
["錯別字", data['錯別字']['level'], data['錯別字']['explanation']]
|
1154 |
]
|
1155 |
-
|
1156 |
-
|
1157 |
# 綜合評分
|
1158 |
grade = assign_grade(data['主題與內容']['level'], data['段落結構']['level'], data['遣詞造句']['level'], data['錯別字']['level'])
|
1159 |
grade_content_text = f"# 綜合評分:{grade}"
|
@@ -1163,13 +1152,31 @@ def get_chinese_paragraph_evaluate_content(model, sys_content, paragraph, user_g
|
|
1163 |
feedback_match = re.search(r"綜合回饋(.*?)評分標準與回饋", content_text, re.DOTALL)
|
1164 |
feedback_text = feedback_match.group(1).strip() if feedback_match else ""
|
1165 |
table_data.append(["綜合評分", grade, feedback_text])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1166 |
|
1167 |
return total_content_text, content_table
|
1168 |
|
1169 |
def get_chinese_paragraph_refine_evaluate_content(model, sys_content, paragraph_1, paragraph_2, user_refine_paragraph_prompt):
|
1170 |
verify_string_length(paragraph_1)
|
1171 |
verify_string_length(paragraph_2)
|
1172 |
-
verify_moderation(paragraph_1+paragraph_2)
|
1173 |
|
1174 |
user_content = f"""
|
1175 |
sys_content: {sys_content}
|
@@ -1180,28 +1187,9 @@ def get_chinese_paragraph_refine_evaluate_content(model, sys_content, paragraph_
|
|
1180 |
---
|
1181 |
{user_refine_paragraph_prompt}
|
1182 |
"""
|
1183 |
-
|
1184 |
-
print(f"====generate_paragraph_evaluate====")
|
1185 |
-
print(content)
|
1186 |
-
|
1187 |
-
content_list = content.split("```json")
|
1188 |
-
content_text = content_list[0]
|
1189 |
-
print(f"content_text: {content_text}")
|
1190 |
-
content_json = content_list[1].replace("```", "")
|
1191 |
-
print(f"content_json: {content_json}")
|
1192 |
-
|
1193 |
-
data = json.loads(content_json)["results"]
|
1194 |
-
headers = ["架構", "評分", "解釋"]
|
1195 |
-
table_data = [
|
1196 |
-
["主題與內容", data['主題與內容']['level'], data['主題與內容']['explanation']],
|
1197 |
-
["段落結構", data['段落結構']['level'], data['段落結構']['explanation']],
|
1198 |
-
["遣詞造句", data['遣詞造句']['level'], data['遣詞造句']['explanation']],
|
1199 |
-
["錯別字", data['錯別字']['level'], data['錯別字']['explanation']]
|
1200 |
-
]
|
1201 |
|
1202 |
-
|
1203 |
-
|
1204 |
-
return content_text, gr_update
|
1205 |
|
1206 |
def generate_content_by_open_ai_assistant(user_content, thread_id=None, model_name=None):
|
1207 |
verify_moderation(user_content)
|
@@ -3204,7 +3192,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3204 |
)
|
3205 |
|
3206 |
chinese_full_paragraph_evaluate_button.click(
|
3207 |
-
fn=
|
3208 |
inputs=[model, chinese_full_paragraph_sys_content_input, chinese_full_paragraph_input, user_generate_chinese_full_paragraph_evaluate_prompt],
|
3209 |
outputs=[chinese_full_paragraph_evaluate_output_text, chinese_full_paragraph_evaluate_output_table]
|
3210 |
).then(
|
|
|
1123 |
# 預設為 🟡
|
1124 |
return "🟡"
|
1125 |
|
1126 |
+
def get_chinese_paragraph_evaluate_content(model, user_content):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1127 |
content = generate_content_by_open_ai_assistant(user_content, thread_id=None, model_name=model)
|
1128 |
print(f"====generate_paragraph_evaluate====")
|
1129 |
print(content)
|
|
|
1142 |
["遣詞造句", data['遣詞造句']['level'], data['遣詞造句']['explanation']],
|
1143 |
["錯別字", data['錯別字']['level'], data['錯別字']['explanation']]
|
1144 |
]
|
1145 |
+
|
|
|
1146 |
# 綜合評分
|
1147 |
grade = assign_grade(data['主題與內容']['level'], data['段落結構']['level'], data['遣詞造句']['level'], data['錯別字']['level'])
|
1148 |
grade_content_text = f"# 綜合評分:{grade}"
|
|
|
1152 |
feedback_match = re.search(r"綜合回饋(.*?)評分標準與回饋", content_text, re.DOTALL)
|
1153 |
feedback_text = feedback_match.group(1).strip() if feedback_match else ""
|
1154 |
table_data.append(["綜合評分", grade, feedback_text])
|
1155 |
+
|
1156 |
+
content_table = gr.update(value=table_data, headers=headers, visible=True)
|
1157 |
+
|
1158 |
+
return total_content_text, content_table
|
1159 |
+
|
1160 |
+
|
1161 |
+
def get_chinese_paragraph_1st_evaluate_content(model, sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
|
1162 |
+
verify_string_length(paragraph)
|
1163 |
+
verify_moderation(paragraph)
|
1164 |
+
|
1165 |
+
user_content = f"""
|
1166 |
+
sys_content: {sys_content}
|
1167 |
+
---
|
1168 |
+
paragraph is: {paragraph}
|
1169 |
+
---
|
1170 |
+
{user_generate_paragraph_evaluate_prompt}
|
1171 |
+
"""
|
1172 |
+
total_content_text, content_table = get_chinese_paragraph_evaluate_content(model, user_content)
|
1173 |
|
1174 |
return total_content_text, content_table
|
1175 |
|
1176 |
def get_chinese_paragraph_refine_evaluate_content(model, sys_content, paragraph_1, paragraph_2, user_refine_paragraph_prompt):
|
1177 |
verify_string_length(paragraph_1)
|
1178 |
verify_string_length(paragraph_2)
|
1179 |
+
verify_moderation(paragraph_1 + paragraph_2)
|
1180 |
|
1181 |
user_content = f"""
|
1182 |
sys_content: {sys_content}
|
|
|
1187 |
---
|
1188 |
{user_refine_paragraph_prompt}
|
1189 |
"""
|
1190 |
+
total_content_text, content_table = get_chinese_paragraph_evaluate_content(model, user_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1191 |
|
1192 |
+
return total_content_text, content_table
|
|
|
|
|
1193 |
|
1194 |
def generate_content_by_open_ai_assistant(user_content, thread_id=None, model_name=None):
|
1195 |
verify_moderation(user_content)
|
|
|
3192 |
)
|
3193 |
|
3194 |
chinese_full_paragraph_evaluate_button.click(
|
3195 |
+
fn=get_chinese_paragraph_1st_evaluate_content,
|
3196 |
inputs=[model, chinese_full_paragraph_sys_content_input, chinese_full_paragraph_input, user_generate_chinese_full_paragraph_evaluate_prompt],
|
3197 |
outputs=[chinese_full_paragraph_evaluate_output_text, chinese_full_paragraph_evaluate_output_table]
|
3198 |
).then(
|