CoolFace
Apppublic

youngtsai/dialogue_generator

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
50 commits on main
b7db8103y ago

refactor

youngtsai
00605bc3y ago

client = OpenAI(api_key=OPEN_AI_KEY)

youngtsai
ea01f673y ago

cefr_level

youngtsai
d292fe43y ago

with gr.Blocks(theme=gr.themes.Soft()) as demo: # 使用 'light' 主题作为默认值

youngtsai
053e3d33y ago

with gr.Blocks(theme=gr.themes.Base()) as demo: # 使用 'light' 主题作为默认值

youngtsai
21e7f293y ago

with gr.Blocks(theme=gr.themes.Glass()) as demo: # 使用 'light' 主题作为默认值

youngtsai
e1837643y ago

with gr.Blocks(theme=gr.themes.Soft()) as demo: # 使用 'light' 主题作为默认值

youngtsai
73315d13y ago

with gr.Blocks(theme=gr.themes.Default()) as demo: # 使用 'light' 主题作为默认值

youngtsai
759d6ff3y ago

with gr.Blocks(theme=gr.themes.Soft()) as demo: # 使用 'light' 主题作为默认值

youngtsai
cbd6f643y ago

with gr.Row(theme=gr.themes.Soft()):

youngtsai
e9a77463y ago

clear_button.click(lambda: [[],None,""], None, [chat_output, json_file, json_textbox], queue=False)

youngtsai
15531a13y ago

clear_button.click(lambda: ["","path/to/empty.txt",""], None, [chat_output, json_file, json_textbox], queue=False)

youngtsai
cc390c13y ago

clear_button.click(lambda: ["","",""], None, [chat_output, json_file, json_textbox], queue=False)

youngtsai
b0529803y ago

clear_button = gr.Button("Clear")

youngtsai
1858dc43y ago

submit_button = gr.Button("Submit", type="submit")

youngtsai
536f8a93y ago

submit_button.click(

youngtsai
22a7db53y ago

submit_button = gr.Button("Submit", style={"background-color": "#FFA500", "color": "white"})

youngtsai
0de648e3y ago

with gr.Column(scale=2): # 2/3 的宽度

youngtsai
d4002993y ago

refactor

youngtsai
cc31c5b3y ago

json_textbox = gr.Textbox(readonly=True, label="對話 JSON 內容", lines=10)

youngtsai
eee5af33y ago

demo.launch(inline=False, share=True)

youngtsai
8d56c8c3y ago

with gr.Blocks(theme="light") as demo: # 使用 'light' 主题作为默认值

youngtsai
50c9cb23y ago

layout = gr.Row(

youngtsai
833774e3y ago

layout="1:3" # 新增這一行

youngtsai
3dae2973y ago

readonly=True, label="對話 JSON 內容", lines=10

youngtsai
f4819db3y ago

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: \".....\"}}]"

youngtsai
d4dc5f03y ago

delete audio

youngtsai
635f86b3y ago

def detect_language(text):

youngtsai
dc702e13y ago

azure-cognitiveservices-speech

youngtsai
16e04ca3y ago

speech_config = speechsdk.SpeechConfig(subscription=AZURE_API_KEY, region=AZURE_REGION)

youngtsai
7fac4f23y ago

import pyttsx3

youngtsai
8d757093y ago

engine = pyttsx3.init()

youngtsai
89c580c3y ago

audio_path = dialogue_to_audio(structured_dialogue, role1_gender, role2_gender)

youngtsai
a2e3e4d3y ago

def dialogue_to_audio(dialogue, role1_gender, role2_gender):

youngtsai
71cee5c3y ago

def main_function(password: str, theme: str, language: str, method: str, rounds: int, role1: str, role1_gender: str, role2: str, role2_gender: str):

youngtsai
6ac85f03y ago

def main_function(password: str, theme: str, language: str, method: str, rounds: int, role1_data: tuple, role2_data: tuple):

youngtsai
cb575a53y ago

text = " ".join([f"{item['content']}" for item in dialogue])

youngtsai
cb56cc73y ago

role1_content = f"{structured_dialogue[i]['content']}"

youngtsai
46d07093y ago

dialogue = create_chat_dialogue(rounds, role1, role2, theme, language)

youngtsai
a48f81b3y ago

def create_chat_dialogue(rounds, role1, role2, theme, language):

youngtsai
acdf0a83y ago

gr.components.Dropdown(choices=["中文", "英文"], label="語言"),

youngtsai
1f9274c3y ago

import gradio as gr

youngtsai
e3ecbca3y ago

prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。(1輪對話的定義是 {role1} 和 {role2} 各說一句話。)以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"{role1}\", content: \".....\"}}, {{role:\"{role2}\", content: \".....\"}}]"

youngtsai
fc2ceb83y ago

sys_content = f"你是一個英文家教,請用英文生成對話,請嚴格控制 {rounds} 輪對話的長度。 1輪對話的定義是 {role1} 和 {role2} 各說一句話。"

youngtsai
c62c7813y ago

sys_content = f"你是一個英文家教,請用英文生成對話,請嚴格控制 {rounds} 輪對話的長度。"

youngtsai
1e259ff3y ago

prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"{role1}\", content: \".....\"}}, {{role:\"{role2}\", content: \".....\"}}]"

youngtsai
c17ed503y ago

dialogue = validate_and_correct_chat(data=extract_json, roles=[role1, role2], rounds=rounds)

youngtsai
c2cda0e3y ago

roles = [role1, role2]

youngtsai
3f9e47f3y ago

dialogue = validate_and_correct_chat(extract_json, roles=[role1, role2], rounds)

youngtsai
500d5003y ago

prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role1:\"{role1}\", content: \".....\"}}, {{role2:\"{role2}\", content: \".....\"}}]"

youngtsai