-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeaking.py
More file actions
370 lines (220 loc) · 25 KB
/
Copy pathspeaking.py
File metadata and controls
370 lines (220 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
def check(user_ans):
model = genai.GenerativeModel(model_name='gemini-pro')
# 格式化成有序列表
insert_list = "\n".join([f"{i + 1}. {ans}" for i, ans in enumerate(user_ans)])
prompt = f"These are four speaking responses provided by a respondent. Please evaluate them based on the TOEFL Speaking scoring standards, and then provide a composite score(don't give me each repsonse score). The score should range from 0 to 30.『{insert_list}』"
response = model.generate_content(prompt)
return response.text
# In[23]:
get_ipython().system('jupyter nbconvert --to script speak.ipynb')
# In[ ]:
def generate_speak_quiz(previous_grade):
import textwrap
import google.generativeai as genai
genai.configure(api_key='AIzaSyDW2edNQ1Ra2_MQYPTHjrtTTg2gjbPjrHs')
model = genai.GenerativeModel(model_name='gemini-pro')
# 根據分數生成提示詞
if past_score == -1:
prompt = '''Generate six TOEFL Independent Speaking task that tests the user's English proficiency. (Separate each question with the @ symbol and make sure your task won't have copyrighted material and Label each question with its corresponding number.)
here is an example :『**1. Good Idea**
Do you agree that it's a good idea to eliminate the use of physical money in favor of digital payments? Provide specific reasons to support your opinion.
@
**2. Campus-Related Topic**
**Announcement:**
To all students:
We are excited to announce the launch of a new program for students to gain practical work experience while completing their studies. The Work-Study Program will allow students to work part-time on campus in various departments and offices.
Benefits of the program include:
* Gain valuable work experience
* Earn money to help cover expenses
* Develop professional skills
* Enhance your resume
If you are interested in participating, please visit the Student Services Office to complete an application.
@
**3. Dialogue Script**
**Student 1:** Did you hear about the new Work-Study Program?
**Student 2:** Yeah, it sounds great! I could really use some extra money, and it would be cool to get some real-world experience before graduating.
**Student 1:** I agree. It's a perfect opportunity to practice the skills we're learning in class and make ourselves more competitive in the job market.
**Student 2:** I'm not so sure. I'm already pretty busy with classes and extracurriculars. I don't want to take on too much.
**Student 1:** I understand. But it's just a part-time job. It's not like it's going to take over your life. And it's only for a semester or two.
**Student 2:** I guess you're right. It might be worth it in the long run.
@
**4. Academic Topic**
**Passage:**
The concept of *locus of control* refers to the extent to which an individual believes that they have control over the events in their lives. People with an internal locus of control believe that they are in charge of their own destiny, while people with an external locus of control believe that external forces determine their outcomes.
@
**5. Lecture Script**
**Professor:** The concept of locus of control is a fundamental one in psychology. It is often used to explain why some people are more successful than others.
People with an internal locus of control tend to be more successful because they believe that they are in control of their lives. This means they are more likely to set goals, take risks, and persevere in the face of challenges.
People with an external locus of control, on the other hand, tend to be less successful because they believe that their lives are controlled by external forces. This means they are more likely to give up when things get tough, and they are less likely to take responsibility for their own actions.
@
**6. Academic Lecture**
**Lecture Topic:** The Rise of Social Media in the 21st Century
**Lecture:**
Social media has become an increasingly important part of our lives in the 21st century. It has changed the way we communicate, interact, and learn.
There are many benefits to social media. For example, it can help us stay connected with friends and family who live far away. It can also be a great tool for learning and staying informed about the world around us.
However, there are also some downsides to social media. For example, it can be a source of cyberbullying and other forms of online harassment. It can also be addictive, and it can be difficult to find a balance between online and offline life.
It is important to be aware of both the benefits and the risks of social media. By using social media wisely, we can reap its benefits while avoiding its pitfalls.
』
The First task should Include a question in one of the following formats: Agree/Disagree, Paired Choice, or Good Idea. The task should be relevant to everyday life or social topics."
The Second task should involving a campus-related topic. Provide passage that **must reach 150 words** about a campus announcement or a student letter (e.g., policy change, event, or issue).
the third task should involving a dialogue script that **must reach 300 words** between two students discussing their opinions on the announcement, where one agrees and the other disagrees. Ensure the reasons are clear and detailed."
The fourth task should involving an academic topic. Provide a passage that **must reach 150 words** explaining a specific academic term or concept.
The Fifth task should involving a lecture script that **must reach 300 words** by a professor that elaborates on the concept using specific examples or scenarios. Ensure the professor's explanation ties back to the text.
The Sixth task featuring a lecture. Write an academic lecture that **must reach 300 words** on a specific topic in science, history, or social studies. Ensure the lecture is clear, organized, and includes supporting details and examples.'''
if 26 <= previous_grade <= 30:
prompt = '''Generate six TOEFL Independent Speaking task that suitable for an advanced English learner. The question should involve abstract thinking or analytical skills, such as discussing global issues, moral dilemmas, or personal philosophies. (Separate each question with the @ symbol and make sure your task won't have copyrighted material and Label each question with its corresponding number.)
here is an example :『**1. Good Idea**
Do you agree that it's a good idea to eliminate the use of physical money in favor of digital payments? Provide specific reasons to support your opinion.
@
**2. Campus-Related Topic**
**Announcement:**
To all students:
We are excited to announce the launch of a new program for students to gain practical work experience while completing their studies. The Work-Study Program will allow students to work part-time on campus in various departments and offices.
Benefits of the program include:
* Gain valuable work experience
* Earn money to help cover expenses
* Develop professional skills
* Enhance your resume
If you are interested in participating, please visit the Student Services Office to complete an application.
@
**3. Dialogue Script**
**Student 1:** Did you hear about the new Work-Study Program?
**Student 2:** Yeah, it sounds great! I could really use some extra money, and it would be cool to get some real-world experience before graduating.
**Student 1:** I agree. It's a perfect opportunity to practice the skills we're learning in class and make ourselves more competitive in the job market.
**Student 2:** I'm not so sure. I'm already pretty busy with classes and extracurriculars. I don't want to take on too much.
**Student 1:** I understand. But it's just a part-time job. It's not like it's going to take over your life. And it's only for a semester or two.
**Student 2:** I guess you're right. It might be worth it in the long run.
@
**4. Academic Topic**
**Passage:**
The concept of *locus of control* refers to the extent to which an individual believes that they have control over the events in their lives. People with an internal locus of control believe that they are in charge of their own destiny, while people with an external locus of control believe that external forces determine their outcomes.
@
**5. Lecture Script**
**Professor:** The concept of locus of control is a fundamental one in psychology. It is often used to explain why some people are more successful than others.
People with an internal locus of control tend to be more successful because they believe that they are in control of their lives. This means they are more likely to set goals, take risks, and persevere in the face of challenges.
People with an external locus of control, on the other hand, tend to be less successful because they believe that their lives are controlled by external forces. This means they are more likely to give up when things get tough, and they are less likely to take responsibility for their own actions.
@
**6. Academic Lecture**
**Lecture Topic:** The Rise of Social Media in the 21st Century
**Lecture:**
Social media has become an increasingly important part of our lives in the 21st century. It has changed the way we communicate, interact, and learn.
There are many benefits to social media. For example, it can help us stay connected with friends and family who live far away. It can also be a great tool for learning and staying informed about the world around us.
However, there are also some downsides to social media. For example, it can be a source of cyberbullying and other forms of online harassment. It can also be addictive, and it can be difficult to find a balance between online and offline life.
It is important to be aware of both the benefits and the risks of social media. By using social media wisely, we can reap its benefits while avoiding its pitfalls. 』
The First task should Include a question in one of the following formats: Agree/Disagree, Paired Choice, or Good Idea. The task should be relevant to everyday life or social topics."
The Second task should involving a campus-related topic. Provide passage that **must reach 150 words** about a campus announcement or a student letter (e.g., policy change, event, or issue).
the third task should involving a dialogue script that **must reach 300 words** between two students discussing their opinions on the announcement, where one agrees and the other disagrees. Ensure the reasons are clear and detailed."
The fourth task should involving an academic topic. Provide a passage that **must reach 150 words** explaining a specific academic term or concept.
The Fifth task should involving a lecture script that **must reach 300 words** by a professor that elaborates on the concept using specific examples or scenarios. Ensure the professor's explanation ties back to the text.
The Sixth task featuring a lecture. Write an academic lecture that **must reach 300 words** on a specific topic in science, history, or social studies. Ensure the lecture is clear, organized, and includes supporting details and examples.'''
elif 18 <= previous_grade <= 25:
prompt = '''Generate six moderately challenging TOEFL Independent Speaking task. requiring a clear opinion with some supporting details. Avoid overly complex vocabulary or ideas. (Separate each question with the @ symbol and make sure your task won't have copyrighted material and Label each question with its corresponding number.)
The First task should Include a question in one of the following formats: Agree/Disagree, Paired Choice, or Good Idea. The task should be relevant to everyday life or social topics."
The Second task should involving a campus-related topic. Provide passage that **must reach 150 words** about a campus announcement or a student letter (e.g., policy change, event, or issue).
the third task should involving a dialogue script that **must reach 300 words** between two students discussing their opinions on the announcement, where one agrees and the other disagrees. Ensure the reasons are clear and detailed."
The fourth task should involving an academic topic. Provide a passage that **must reach 150 words** explaining a specific academic term or concept.
The Fifth task should involving a lecture script that **must reach 300 words** by a professor that elaborates on the concept using specific examples or scenarios. Ensure the professor's explanation ties back to the text.
The Sixth task featuring a lecture. Write an academic lecture that **must reach 300 words** on a specific topic in science, history, or social studies. Ensure the lecture is clear, organized, and includes supporting details and examples.'''
elif 10 <= previous_grade <= 17:
prompt = '''Generate six simple TOEFL Independent Speaking task.focusing on basic sentence structures. (Separate each question with the @ symbol and make sure your task won't have copyrighted material and Label each question with its corresponding number.)
here is an example :『**1. Good Idea**
Do you agree that it's a good idea to eliminate the use of physical money in favor of digital payments? Provide specific reasons to support your opinion.
@
**2. Campus-Related Topic**
**Announcement:**
To all students:
We are excited to announce the launch of a new program for students to gain practical work experience while completing their studies. The Work-Study Program will allow students to work part-time on campus in various departments and offices.
Benefits of the program include:
* Gain valuable work experience
* Earn money to help cover expenses
* Develop professional skills
* Enhance your resume
If you are interested in participating, please visit the Student Services Office to complete an application.
@
**3. Dialogue Script**
**Student 1:** Did you hear about the new Work-Study Program?
**Student 2:** Yeah, it sounds great! I could really use some extra money, and it would be cool to get some real-world experience before graduating.
**Student 1:** I agree. It's a perfect opportunity to practice the skills we're learning in class and make ourselves more competitive in the job market.
**Student 2:** I'm not so sure. I'm already pretty busy with classes and extracurriculars. I don't want to take on too much.
**Student 1:** I understand. But it's just a part-time job. It's not like it's going to take over your life. And it's only for a semester or two.
**Student 2:** I guess you're right. It might be worth it in the long run.
@
**4. Academic Topic**
**Passage:**
The concept of *locus of control* refers to the extent to which an individual believes that they have control over the events in their lives. People with an internal locus of control believe that they are in charge of their own destiny, while people with an external locus of control believe that external forces determine their outcomes.
@
**5. Lecture Script**
**Professor:** The concept of locus of control is a fundamental one in psychology. It is often used to explain why some people are more successful than others.
People with an internal locus of control tend to be more successful because they believe that they are in control of their lives. This means they are more likely to set goals, take risks, and persevere in the face of challenges.
People with an external locus of control, on the other hand, tend to be less successful because they believe that their lives are controlled by external forces. This means they are more likely to give up when things get tough, and they are less likely to take responsibility for their own actions.
@
**6. Academic Lecture**
**Lecture Topic:** The Rise of Social Media in the 21st Century
**Lecture:**
Social media has become an increasingly important part of our lives in the 21st century. It has changed the way we communicate, interact, and learn.
There are many benefits to social media. For example, it can help us stay connected with friends and family who live far away. It can also be a great tool for learning and staying informed about the world around us.
However, there are also some downsides to social media. For example, it can be a source of cyberbullying and other forms of online harassment. It can also be addictive, and it can be difficult to find a balance between online and offline life.
It is important to be aware of both the benefits and the risks of social media. By using social media wisely, we can reap its benefits while avoiding its pitfalls. 』
The First task should Include a question in one of the following formats: Agree/Disagree, Paired Choice, or Good Idea. The task should be relevant to everyday life or social topics."
The Second task should involving a campus-related topic. Provide passage that **must reach 150 words** about a campus announcement or a student letter (e.g., policy change, event, or issue).
the third task should involving a dialogue script that **must reach 300 words** between two students discussing their opinions on the announcement, where one agrees and the other disagrees. Ensure the reasons are clear and detailed."
The fourth task should involving an academic topic. Provide a passage that **must reach 150 words** explaining a specific academic term or concept.
The Fifth task should involving a lecture script that **must reach 300 words** by a professor that elaborates on the concept using specific examples or scenarios. Ensure the professor's explanation ties back to the text.
The Sixth task featuring a lecture. Write an academic lecture that **must reach 300 words** on a specific topic in science, history, or social studies. Ensure the lecture is clear, organized, and includes supporting details and examples.'''
elif 0 <= previous_grade <= 9:
prompt = '''Generate six TOEFL Independent Speaking task that suitable for a beginner in English. The question should involve basic personal preferences or descriptive topics, such as favorite food, daily routines, or a memorable day.. (Separate each question with the @ symbol and make sure your task won't have copyrighted material and Label each question with its corresponding number.)
here is an example :『**1. Good Idea**
Do you agree that it's a good idea to eliminate the use of physical money in favor of digital payments? Provide specific reasons to support your opinion.
@
**2. Campus-Related Topic**
**Announcement:**
To all students:
We are excited to announce the launch of a new program for students to gain practical work experience while completing their studies. The Work-Study Program will allow students to work part-time on campus in various departments and offices.
Benefits of the program include:
* Gain valuable work experience
* Earn money to help cover expenses
* Develop professional skills
* Enhance your resume
If you are interested in participating, please visit the Student Services Office to complete an application.
@
**3. Dialogue Script**
**Student 1:** Did you hear about the new Work-Study Program?
**Student 2:** Yeah, it sounds great! I could really use some extra money, and it would be cool to get some real-world experience before graduating.
**Student 1:** I agree. It's a perfect opportunity to practice the skills we're learning in class and make ourselves more competitive in the job market.
**Student 2:** I'm not so sure. I'm already pretty busy with classes and extracurriculars. I don't want to take on too much.
**Student 1:** I understand. But it's just a part-time job. It's not like it's going to take over your life. And it's only for a semester or two.
**Student 2:** I guess you're right. It might be worth it in the long run.
@
**4. Academic Topic**
**Passage:**
The concept of *locus of control* refers to the extent to which an individual believes that they have control over the events in their lives. People with an internal locus of control believe that they are in charge of their own destiny, while people with an external locus of control believe that external forces determine their outcomes.
@
**5. Lecture Script**
**Professor:** The concept of locus of control is a fundamental one in psychology. It is often used to explain why some people are more successful than others.
People with an internal locus of control tend to be more successful because they believe that they are in control of their lives. This means they are more likely to set goals, take risks, and persevere in the face of challenges.
People with an external locus of control, on the other hand, tend to be less successful because they believe that their lives are controlled by external forces. This means they are more likely to give up when things get tough, and they are less likely to take responsibility for their own actions.
@
**6. Academic Lecture**
**Lecture Topic:** The Rise of Social Media in the 21st Century
**Lecture:**
Social media has become an increasingly important part of our lives in the 21st century. It has changed the way we communicate, interact, and learn.
There are many benefits to social media. For example, it can help us stay connected with friends and family who live far away. It can also be a great tool for learning and staying informed about the world around us.
However, there are also some downsides to social media. For example, it can be a source of cyberbullying and other forms of online harassment. It can also be addictive, and it can be difficult to find a balance between online and offline life.
It is important to be aware of both the benefits and the risks of social media. By using social media wisely, we can reap its benefits while avoiding its pitfalls. 』
The First task should Include a question in one of the following formats: Agree/Disagree, Paired Choice, or Good Idea. The task should be relevant to everyday life or social topics."
The Second task should involving a campus-related topic. Provide passage that **must reach 150 words** about a campus announcement or a student letter (e.g., policy change, event, or issue).
the third task should involving a dialogue script that **must reach 300 words** between two students discussing their opinions on the announcement, where one agrees and the other disagrees. Ensure the reasons are clear and detailed."
The fourth task should involving an academic topic. Provide a passage that **must reach 150 words** explaining a specific academic term or concept.
The Fifth task should involving a lecture script that **must reach 300 words** by a professor that elaborates on the concept using specific examples or scenarios. Ensure the professor's explanation ties back to the text.
The Sixth task featuring a lecture. Write an academic lecture that **must reach 300 words** on a specific topic in science, history, or social studies. Ensure the lecture is clear, organized, and includes supporting details and examples.'''
try:
response = model.generate_content(prompt)
except Exception as e:
return "Your score should be between 0 and 30."
else:
tasks = response.text.split('@')
cleaned_tasks = [task.strip() for task in tasks if task.strip()]
return cleaned_tasks #回傳結果是一個list = [read , read , listen , read , listen , listen]