youngtsai/dialogue_generator
refactor
client = OpenAI(api_key=OPEN_AI_KEY)
cefr_level
with gr.Blocks(theme=gr.themes.Soft()) as demo: # 使用 'light' 主题作为默认值
with gr.Blocks(theme=gr.themes.Base()) as demo: # 使用 'light' 主题作为默认值
with gr.Blocks(theme=gr.themes.Glass()) as demo: # 使用 'light' 主题作为默认值
with gr.Blocks(theme=gr.themes.Soft()) as demo: # 使用 'light' 主题作为默认值
with gr.Blocks(theme=gr.themes.Default()) as demo: # 使用 'light' 主题作为默认值
with gr.Blocks(theme=gr.themes.Soft()) as demo: # 使用 'light' 主题作为默认值
with gr.Row(theme=gr.themes.Soft()):
clear_button.click(lambda: [[],None,""], None, [chat_output, json_file, json_textbox], queue=False)
clear_button.click(lambda: ["","path/to/empty.txt",""], None, [chat_output, json_file, json_textbox], queue=False)
clear_button.click(lambda: ["","",""], None, [chat_output, json_file, json_textbox], queue=False)
clear_button = gr.Button("Clear")
submit_button = gr.Button("Submit", type="submit")
submit_button.click(
submit_button = gr.Button("Submit", style={"background-color": "#FFA500", "color": "white"})
with gr.Column(scale=2): # 2/3 的宽度
refactor
json_textbox = gr.Textbox(readonly=True, label="對話 JSON 內容", lines=10)
demo.launch(inline=False, share=True)
with gr.Blocks(theme="light") as demo: # 使用 'light' 主题作为默认值
layout = gr.Row(
layout="1:3" # 新增這一行
readonly=True, label="對話 JSON 內容", lines=10
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: \".....\"}}]"
delete audio
def detect_language(text):
azure-cognitiveservices-speech
speech_config = speechsdk.SpeechConfig(subscription=AZURE_API_KEY, region=AZURE_REGION)
import pyttsx3
engine = pyttsx3.init()
audio_path = dialogue_to_audio(structured_dialogue, role1_gender, role2_gender)
def dialogue_to_audio(dialogue, role1_gender, role2_gender):
def main_function(password: str, theme: str, language: str, method: str, rounds: int, role1: str, role1_gender: str, role2: str, role2_gender: str):
def main_function(password: str, theme: str, language: str, method: str, rounds: int, role1_data: tuple, role2_data: tuple):
text = " ".join([f"{item['content']}" for item in dialogue])
role1_content = f"{structured_dialogue[i]['content']}"
dialogue = create_chat_dialogue(rounds, role1, role2, theme, language)
def create_chat_dialogue(rounds, role1, role2, theme, language):
gr.components.Dropdown(choices=["中文", "英文"], label="語言"),
import gradio as gr
prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。(1輪對話的定義是 {role1} 和 {role2} 各說一句話。)以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"{role1}\", content: \".....\"}}, {{role:\"{role2}\", content: \".....\"}}]"
sys_content = f"你是一個英文家教,請用英文生成對話,請嚴格控制 {rounds} 輪對話的長度。 1輪對話的定義是 {role1} 和 {role2} 各說一句話。"
sys_content = f"你是一個英文家教,請用英文生成對話,請嚴格控制 {rounds} 輪對話的長度。"
prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"{role1}\", content: \".....\"}}, {{role:\"{role2}\", content: \".....\"}}]"
dialogue = validate_and_correct_chat(data=extract_json, roles=[role1, role2], rounds=rounds)
roles = [role1, role2]
dialogue = validate_and_correct_chat(extract_json, roles=[role1, role2], rounds)
prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role1:\"{role1}\", content: \".....\"}}, {{role2:\"{role2}\", content: \".....\"}}]"
