Noracle commited on
Commit
5ed6ee9
·
verified ·
1 Parent(s): dee4efc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
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("作文题目(Prompt", height=100)
46
- essay = st.text_area("作文正文(Essay", height=300)
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
- # 注意:回归模型输出为logits,需手动转换为连续分数(示例假设输出为0-9的连续值)
59
- # 实际需根据模型输出调整,例如是否使用sigmoid或直接返回logits
60
- input_text = f"评分任务:题目:{prompt} 作文:{essay}"
61
  score_output = pipe1(input_text)[0]
62
- # 示例处理:假设模型输出包含"label"为分数(需根据实际模型输出调整)
63
- # 若输出为logits,可能需要归一化到0-9区间
64
- overall_score = score_output.get('score', 0.0) * 9.0 # 示例转换,需根据模型实际输出调整
65
- overall_score = round(overall_score, 1) # 保留一位小数
 
 
 
66
 
67
  # Pipeline 2: 生成详细反馈
68
  pipe2 = load_pipeline2_model()
69
- input_text2 = f"生成反馈:题目:{prompt} 作文:{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("### 评估结果")
75
- st.markdown(f"#### 整体分数:**{overall_score}/9.0**")
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__":