Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ def load_pipeline1_model():
|
|
8 |
model_name = "yitongwu73/finetuned-roberta-base"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
11 |
-
# 回归任务需手动设置pipeline类型为"text-classification"并指定回归参数
|
12 |
pipe = pipeline(
|
13 |
"text-classification",
|
14 |
model=model,
|
@@ -32,48 +31,49 @@ def load_pipeline2_model():
|
|
32 |
|
33 |
def main():
|
34 |
st.set_page_config(
|
35 |
-
page_title="IELTS
|
36 |
page_icon="📝",
|
37 |
layout="wide"
|
38 |
)
|
39 |
|
40 |
-
st.title("NewChannel IELTS
|
41 |
-
st.markdown("###
|
42 |
|
43 |
# 输入框布局
|
44 |
with st.form("evaluation_form"):
|
45 |
-
prompt = st.text_area("
|
46 |
-
essay = st.text_area("
|
47 |
-
submitted = st.form_submit_button("
|
48 |
|
49 |
if submitted:
|
50 |
if not prompt or not essay:
|
51 |
-
st.warning("
|
52 |
return
|
53 |
|
54 |
# 显示加载状态
|
55 |
-
with st.spinner("
|
56 |
# Pipeline 1: 获取整体评分
|
57 |
pipe1 = load_pipeline1_model()
|
58 |
-
|
59 |
-
# 实际需根据模型输出调整,例如是否使用sigmoid或直接返回logits
|
60 |
-
input_text = f"评分任务:题目:{prompt} 作文:{essay}"
|
61 |
score_output = pipe1(input_text)[0]
|
62 |
-
|
63 |
-
#
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
# Pipeline 2: 生成详细反馈
|
68 |
pipe2 = load_pipeline2_model()
|
69 |
-
input_text2 = f"
|
70 |
feedback_output = pipe2(input_text2, max_length=1024, num_return_sequences=1)[0]
|
71 |
feedback_text = feedback_output['generated_text']
|
72 |
|
73 |
-
#
|
74 |
-
st.markdown("###
|
75 |
-
st.markdown(f"####
|
76 |
-
st.markdown("####
|
77 |
st.markdown(feedback_text)
|
78 |
|
79 |
if __name__ == "__main__":
|
|
|
8 |
model_name = "yitongwu73/finetuned-roberta-base"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
11 |
pipe = pipeline(
|
12 |
"text-classification",
|
13 |
model=model,
|
|
|
31 |
|
32 |
def main():
|
33 |
st.set_page_config(
|
34 |
+
page_title="IELTS Essay Scoring & Feedback System",
|
35 |
page_icon="📝",
|
36 |
layout="wide"
|
37 |
)
|
38 |
|
39 |
+
st.title("NewChannel IELTS Essay Evaluation System")
|
40 |
+
st.markdown("### Please enter your essay prompt and content")
|
41 |
|
42 |
# 输入框布局
|
43 |
with st.form("evaluation_form"):
|
44 |
+
prompt = st.text_area("Essay Prompt", height=100)
|
45 |
+
essay = st.text_area("Essay Content", height=300)
|
46 |
+
submitted = st.form_submit_button("Generate Evaluation Report")
|
47 |
|
48 |
if submitted:
|
49 |
if not prompt or not essay:
|
50 |
+
st.warning("Please complete both the essay prompt and content")
|
51 |
return
|
52 |
|
53 |
# 显示加载状态
|
54 |
+
with st.spinner("Evaluating your essay..."):
|
55 |
# Pipeline 1: 获取整体评分
|
56 |
pipe1 = load_pipeline1_model()
|
57 |
+
input_text = f"Scoring Task: Prompt: {prompt} Essay: {essay}"
|
|
|
|
|
58 |
score_output = pipe1(input_text)[0]
|
59 |
+
|
60 |
+
# 分数映射和转换(保持与之前相同的逻辑)
|
61 |
+
logits = score_output['score']
|
62 |
+
min_logit, max_logit = -5, 5 # 需根据模型实际输出范围调整
|
63 |
+
min_score, max_score = 3.5, 9.0
|
64 |
+
overall_score = ((logits - min_logit) / (max_logit - min_logit)) * (max_score - min_score) + min_score
|
65 |
+
overall_score = round(overall_score * 2) / 2 # 保留0.5间隔
|
66 |
|
67 |
# Pipeline 2: 生成详细反馈
|
68 |
pipe2 = load_pipeline2_model()
|
69 |
+
input_text2 = f"Generate Feedback: Prompt: {prompt} Essay: {essay}"
|
70 |
feedback_output = pipe2(input_text2, max_length=1024, num_return_sequences=1)[0]
|
71 |
feedback_text = feedback_output['generated_text']
|
72 |
|
73 |
+
# 展示结果(英文)
|
74 |
+
st.markdown("### Evaluation Results")
|
75 |
+
st.markdown(f"#### Overall Band Score: **{overall_score}/9.0**")
|
76 |
+
st.markdown("#### Detailed Feedback")
|
77 |
st.markdown(feedback_text)
|
78 |
|
79 |
if __name__ == "__main__":
|