Spaces:
Sleeping
Sleeping
Commit
·
97907b3
1
Parent(s):
06b4380
Update app.py
Browse files
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 =
|
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:
|
|
|
|
|
|
|
|
|
|
|
141 |
you should return:
|
142 |
|
143 |
-
Total mark:
|
144 |
------------------------------------------------------------------------------------
|
145 |
Content
|
146 |
|
147 |
-
3 points
|
148 |
|
149 |
- Each picture involves content: ✔️
|
150 |
-
- Each
|
151 |
-
-
|
152 |
|
153 |
-
------------------------------------------------------------------------------------
|
154 |
Organization
|
155 |
|
156 |
-
|
157 |
|
158 |
-
-
|
159 |
-
-
|
160 |
-
-
|
161 |
|
162 |
-
------------------------------------------------------------------------------------
|
163 |
Language
|
164 |
|
165 |
-
|
166 |
|
167 |
*Dimension 1: Complexity*
|
168 |
-
|
169 |
-
-
|
170 |
-
-
|
171 |
-
-
|
172 |
|
173 |
*Dimension 2: Diversity*
|
174 |
-
|
|
|
175 |
|
176 |
*Dimension 3: Accuracy*
|
177 |
-
|
178 |
-
-
|
|
|
|
|
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 |
-
|
262 |
|
263 |
-
|
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(
|
289 |
user_message = query
|
290 |
messages = [
|
291 |
{'role':'system',
|
292 |
'content': system_message},
|
293 |
{'role':'user',
|
294 |
-
'content': f"
|
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 = '''
|