xuyingliKepler commited on
Commit
97907b3
·
1 Parent(s): 06b4380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -6,8 +6,17 @@ from PIL import Image
6
  from transformers import pipeline
7
 
8
 
 
 
 
 
 
 
 
 
 
9
  # 初始化图片描述生成模型
10
- image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
11
 
12
 
13
  # Set OpenAI API key
@@ -40,7 +49,7 @@ def split_image(image, output_dir='.'):
40
  part_img.save(file_path)
41
 
42
  # 生成图片描述
43
- caption = image_to_text(part_img)
44
  results.append((file_path, caption))
45
 
46
  return results
@@ -93,6 +102,9 @@ It rains dogs and cats when they were going to the plane. “What a bad weather!
93
  One days ago, they arrived at there on Saturday.
94
  A local person, who is the photographer, helped they took a photo. They had a happy holiday.
95
 
 
 
 
96
  you should return:
97
 
98
  Total mark: 15 points
@@ -137,45 +149,51 @@ Language Dimension 3: Accuracy
137
  """
138
 
139
  example_2 = """
140
- student essay:In the first picture the family is looking for a maps and magazine of Hawai. In the second picture is raining and the family is took a plane. In the thirt picture the family is in the beach and have sunglasses.
 
 
 
 
 
141
  you should return:
142
 
143
- Total mark: 6 points
144
  ------------------------------------------------------------------------------------
145
  Content
146
 
147
- 3 points
148
 
149
  - Each picture involves content: ✔️
150
- - Each image should have 2-3 sentences; if sub-clauses are used, description can be reduced to 1-2 sentences for each image:
151
- - Writing is partially relevant and some information is not sufficiently conveyed: -
152
 
153
- ------------------------------------------------------------------------------------
154
  Organization
155
 
156
- 1 point
157
 
158
- - Structured writing with a clear introduction, body, and conclusion. The first two sentences provide clear context regarding time, place, individuals, and actions: ✔️
159
- - Less than 90% logical connection between sentences:
160
- - Insufficient use of linkage techniques:
161
 
162
- ------------------------------------------------------------------------------------
163
  Language
164
 
165
- 2 points
166
 
167
  *Dimension 1: Complexity*
168
- - About 30% of words are bi-syllabic or multi-syllabic: ✔️
169
- - Lacks B1 level or above vocabulary:
170
- - Does not incorporate sub-clauses:
171
- - Only one coordinated sentence using "and": -
172
 
173
  *Dimension 2: Diversity*
174
- - Repetitive use of words such as "picture" (3 times), "family" (3 times), and present continuous tense (2 times): ❌
 
175
 
176
  *Dimension 3: Accuracy*
177
- - Two word spelling errors: "Hawai", "thirt". Grammatical errors in 2 places: "is took a plane", "is have sunglasses": ❌
178
- - Can form complete sentences and uses basic words, so the examiner might award an additional 1 point for effort.
 
 
179
  """
180
 
181
  system_message = f'''
@@ -258,9 +276,9 @@ with col1:
258
  st.image(uploaded_image, caption="已上传的图片。", use_column_width=True)
259
  image = Image.open(uploaded_image).convert("RGB")
260
  output_dir = '.'
261
- caption_results = split_image(image, output_dir)
262
 
263
- student_essay = st.text_area(
264
  " 输入你的作文",
265
  height= 400
266
  )
@@ -285,13 +303,13 @@ with col2:
285
  progress_placeholder = st.empty()
286
  progress_text = "开始打分"
287
  my_bar = progress_placeholder.progress(0, text=progress_text)
288
- query = str(student_essay)
289
  user_message = query
290
  messages = [
291
  {'role':'system',
292
  'content': system_message},
293
  {'role':'user',
294
- 'content': f"请记住你的设定和评分标准【{query}】, 三张图片对应的captions分别是:{caption_results}"},]
295
  response = get_completion_from_messages(messages)
296
  my_bar.progress(50, text="开始提供相关素材")
297
  system_message_4 = '''
 
6
  from transformers import pipeline
7
 
8
 
9
+ if "model" not in st.session_state:
10
+ st.session_state.model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
11
+
12
+ if "result" not in st.session_state:
13
+ st.session_state.result = ""
14
+
15
+ if "essay" not in st.session_state:
16
+ st.session_state.essay = ""
17
+
18
  # 初始化图片描述生成模型
19
+ # image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
20
 
21
 
22
  # Set OpenAI API key
 
49
  part_img.save(file_path)
50
 
51
  # 生成图片描述
52
+ caption = st.session_state.model(part_img)
53
  results.append((file_path, caption))
54
 
55
  return results
 
102
  One days ago, they arrived at there on Saturday.
103
  A local person, who is the photographer, helped they took a photo. They had a happy holiday.
104
 
105
+ image content: a cartoon of a family sitting on a couch reading a book,a cartoon drawing of a group of people climbing up a flight of stairs
106
+ ,a cartoon drawing of a family standing on the beach
107
+
108
  you should return:
109
 
110
  Total mark: 15 points
 
149
  """
150
 
151
  example_2 = """
152
+ student essay:
153
+ There is a Jack’s birthday. There are he, his brother, mum and dad. His brother is giving him a ball to football. Next day, Jack and his brother are playing football match. Jack score a goal.
154
+
155
+ image content: cartoon of a family sitting around a table with a birthday cake,cartoon of a man giving a birthday cake to a woman,
156
+ cartoon of a man kicking a soccer ball into a goal
157
+
158
  you should return:
159
 
160
+ Total mark: 9 points
161
  ------------------------------------------------------------------------------------
162
  Content
163
 
164
+ 3 points:
165
 
166
  - Each picture involves content: ✔️
167
+ - Each picture has at least one sentence: ✔️
168
+ - The content is relevant, but the information derived from the image is not exhaustive:
169
 
 
170
  Organization
171
 
172
+ 3 points:
173
 
174
+ - Complete structure with a clear introduction, development, and conclusion: ✔️
175
+ - 50% of the sentences have logical connections: ✔️
176
+ - Contains one to two types of cohesive devices, such as pronouns (e.g., he, his brother) and temporal relations (e.g., next day). The number of cohesive devices used ranges between 2-4 for one type: ✔️
177
 
 
178
  Language
179
 
180
+ 3 points:
181
 
182
  *Dimension 1: Complexity*
183
+
184
+ - Bi-syllabic and multi-syllabic words make up 9%: ✔️
185
+ - All words are common, everyday vocabulary: ✔️
186
+ - No complex sentences or compound sentences:
187
 
188
  *Dimension 2: Diversity*
189
+
190
+ - Repetition of words: "Brother" appears 3 times, "football" appears 2 times: ❌
191
 
192
  *Dimension 3: Accuracy*
193
+
194
+ - No word spelling mistakes: ✔️
195
+ - Did not use past tense: ❌
196
+ - Grammatical errors in four places: "There is a Jack’s birthday", "There are he", "to football", "Jack score": ❌
197
  """
198
 
199
  system_message = f'''
 
276
  st.image(uploaded_image, caption="已上传的图片。", use_column_width=True)
277
  image = Image.open(uploaded_image).convert("RGB")
278
  output_dir = '.'
279
+ st.session_state.result = split_image(image, output_dir)
280
 
281
+ st.session_state.essay = st.text_area(
282
  " 输入你的作文",
283
  height= 400
284
  )
 
303
  progress_placeholder = st.empty()
304
  progress_text = "开始打分"
305
  my_bar = progress_placeholder.progress(0, text=progress_text)
306
+ query = str(st.session_state.essay)
307
  user_message = query
308
  messages = [
309
  {'role':'system',
310
  'content': system_message},
311
  {'role':'user',
312
+ 'content': f"remember your settings student essay:【{query}】, image content:{st.session_state.result}"},]
313
  response = get_completion_from_messages(messages)
314
  my_bar.progress(50, text="开始提供相关素材")
315
  system_message_4 = '''