youngtsai commited on
Commit
ea01f67
·
1 Parent(s): d292fe4

cefr_level

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -54,13 +54,13 @@ def extract_json_from_response(response_text):
54
  raise ValueError("JSON dialogue not found in the response.")
55
 
56
 
57
- def create_chat_dialogue(rounds, role1, role1_gender, role2, role2_gender, theme, language):
58
  openai.api_key = os.environ["OPEN_AI_KEY"]
59
 
60
  # 初始化對話
61
  sentenses_count = int(rounds) * 2
62
  sys_content = f"你是一個{language}家教,請用{language}生成對話"
63
- prompt = f"您將進行一場以{theme}為主題的對話。{role1} (gender: {role1_gender}) 和{role2} (gender: {role2_gender})將是參與者。請依次交談{rounds}輪。(1輪對話的定義是 {role1} 和 {role2} 各說一句話,總共 {sentenses_count} 句話。)以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"{role1}\", \"gender\": {role1_gender} , content: \".....\"}}, {{role:\"{role2}\", \"gender\": {role2_gender}, content: \".....\"}}]"
64
  messages = [
65
  {"role": "system", "content": sys_content},
66
  {"role": "user", "content": prompt}
@@ -88,18 +88,18 @@ def create_chat_dialogue(rounds, role1, role1_gender, role2, role2_gender, theme
88
  return dialogue
89
 
90
 
91
- def generate_dialogue(rounds, method, role1, role1_gender, role2, role2_gender, theme, language):
92
  if method == "auto":
93
- dialogue = create_chat_dialogue(rounds, role1, role1_gender, role2, role2_gender, theme, language)
94
  else:
95
  dialogue = [{"role": role1, "gender": role1_gender, "content": "手動輸入文本 1"}, {"role": role2, "gender": role2_gender , "content": "手動輸入文本 2"}]
96
  return dialogue
97
 
98
- def main_function(password: str, theme: str, language: str, method: str, rounds: int, role1: str, role1_gender: str, role2: str, role2_gender: str):
99
  if password != os.environ.get("PASSWORD", ""):
100
  return "错误的密码,请重新输入。", ""
101
 
102
- structured_dialogue = generate_dialogue(rounds, method, role1, role1_gender, role2, role2_gender, theme, language)
103
 
104
  # Convert structured dialogue for Chatbot component to show "role1: content1" and "role2: content2" side by side
105
  chatbot_dialogue = []
@@ -134,6 +134,7 @@ if __name__ == "__main__":
134
  password = gr.Textbox(label="输入密码", type="password")
135
  theme = gr.Textbox(label="對話主題") # 加入 theme 的輸入框,設定預設值為 '購物'
136
  language = gr.Dropdown(choices=["中文", "英文"], label="語言")
 
137
  generation_mode = gr.Dropdown(choices=["auto", "manual"], label="生成方式")
138
  rounds = gr.Slider(minimum=2, maximum=6, step=2, label="對話輪數")
139
  role1_name = gr.Textbox(label="角色 1 名稱")
@@ -149,7 +150,8 @@ if __name__ == "__main__":
149
  [
150
  password,
151
  theme,
152
- language,
 
153
  generation_mode,
154
  rounds,
155
  role1_name,
 
54
  raise ValueError("JSON dialogue not found in the response.")
55
 
56
 
57
+ def create_chat_dialogue(rounds, role1, role1_gender, role2, role2_gender, theme, language, cefr_level):
58
  openai.api_key = os.environ["OPEN_AI_KEY"]
59
 
60
  # 初始化對話
61
  sentenses_count = int(rounds) * 2
62
  sys_content = f"你是一個{language}家教,請用{language}生成對話"
63
+ prompt = f"您將進行一場以{theme}為主題的對話,請用 cefr_level:{cefr_level} 為對話的程度。{role1} (gender: {role1_gender}) 和{role2} (gender: {role2_gender})將是參與者。請依次交談{rounds}輪。(1輪對話的定義是 {role1} 和 {role2} 各說一句話,總共 {sentenses_count} 句話。)以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"{role1}\", \"gender\": {role1_gender} , content: \".....\"}}, {{role:\"{role2}\", \"gender\": {role2_gender}, content: \".....\"}}]"
64
  messages = [
65
  {"role": "system", "content": sys_content},
66
  {"role": "user", "content": prompt}
 
88
  return dialogue
89
 
90
 
91
+ def generate_dialogue(rounds, method, role1, role1_gender, role2, role2_gender, theme, language, cefr_level):
92
  if method == "auto":
93
+ dialogue = create_chat_dialogue(rounds, role1, role1_gender, role2, role2_gender, theme, language, cefr_level)
94
  else:
95
  dialogue = [{"role": role1, "gender": role1_gender, "content": "手動輸入文本 1"}, {"role": role2, "gender": role2_gender , "content": "手動輸入文本 2"}]
96
  return dialogue
97
 
98
+ def main_function(password: str, theme: str, language: str, cefr_level: str, method: str, rounds: int, role1: str, role1_gender: str, role2: str, role2_gender: str):
99
  if password != os.environ.get("PASSWORD", ""):
100
  return "错误的密码,请重新输入。", ""
101
 
102
+ structured_dialogue = generate_dialogue(rounds, method, role1, role1_gender, role2, role2_gender, theme, language, cefr_level)
103
 
104
  # Convert structured dialogue for Chatbot component to show "role1: content1" and "role2: content2" side by side
105
  chatbot_dialogue = []
 
134
  password = gr.Textbox(label="输入密码", type="password")
135
  theme = gr.Textbox(label="對話主題") # 加入 theme 的輸入框,設定預設值為 '購物'
136
  language = gr.Dropdown(choices=["中文", "英文"], label="語言")
137
+ cefr_level = gr.Dropdown(choices=["A1", "A2", "B1", "B2", "C1", "C2"], label="CEFR Level")
138
  generation_mode = gr.Dropdown(choices=["auto", "manual"], label="生成方式")
139
  rounds = gr.Slider(minimum=2, maximum=6, step=2, label="對話輪數")
140
  role1_name = gr.Textbox(label="角色 1 名稱")
 
150
  [
151
  password,
152
  theme,
153
+ language,
154
+ cefr_level,
155
  generation_mode,
156
  rounds,
157
  role1_name,