-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistening.py
More file actions
61 lines (38 loc) · 2.69 KB
/
Copy pathlistening.py
File metadata and controls
61 lines (38 loc) · 2.69 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
# In[8]:
#generate_listening_quiz(past_score)
def generate_listening_quiz(past_score):
import google.generativeai as genai
import os
import pandas as pd
import json
columns = ['number', 'speech']
df = pd.DataFrame(columns=columns)
df['number'] = range(1, 12)
api_key = 'AIzaSyCzxTThllx9X_KSrGECc9_33QEE8DB45jw'
genai.configure(api_key = api_key)
model = genai.GenerativeModel('gemini-1.5-flash')
prompt_article_conv = "依照TOEFL聽力文章的要求,生成1篇聽力文章,主題為「校園對話」,文章不換行。"
prompt_article_lecture = "依照TOEFL聽力文章的要求,生成1篇聽力文章,主題為「學術演講」,文章不換行。"
article_conv = model.generate_content(prompt_article_conv).text
article_conv = article_conv.replace("\n", "").replace("\r", "")
article_lecture = model.generate_content(prompt_article_lecture).text
article_lecture = article_lecture.replace("\n", "").replace("\r", "")
prompt_questions_conv = "依以下文章{article_conv}生成5題四選一單選題題目,題型分別為「Gist-purpose Question」,「Detail Question」,「Understanding the Speaker’s Attitude Question」,「Understanding the Function of What is Said Question」,「Detail Question」。以JSON格式輸出,欄位順序為:'question', 'A', 'B', 'C', 'D', 'answer', 'question_type’。"
prompt_questions_lecture = "依以下文章{article_lecture}生成6題四選一單選題題目,題型分別為「Gist-purpose Question」,「Detail Question」, 「Understanding Organization Question」, 「Making Inference Questions」, 「Connecting Content Questions」, 「Detail Question」。以JSON格式輸出,欄位順序為:'question', 'A', 'B', 'C', 'D', 'answer', 'question_type'。"
questions_conv = model.generate_content(prompt_questions_conv + article_conv).text
questions_lecture = model.generate_content(prompt_questions_lecture + article_lecture).text
questions_conv_json = questions_conv[8:-4]
questions_conv_dict = json.loads(questions_conv_json)
df_questions_conv = pd.DataFrame(questions_conv_dict)
questions_lecture_json = questions_lecture[8:-4]
questions_lecture_dict = json.loads(questions_lecture_json)
df_questions_lecture = pd.DataFrame(questions_lecture_dict)
df_questions = pd.concat([df_questions_conv, df_questions_lecture], ignore_index=True)
df_questions.to_csv("questions.csv", index=False)
df.loc[0, 'speech'] = article_conv
df.loc[5, 'speech'] = article_lecture
df_listening = pd.concat([df, df_questions], axis=1)
df_listening.to_csv("listening.csv", index=False)
return df_listening
# In[10]:
# In[ ]: