Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ def audio_prompt_to_chatgpt(audio_path):
|
|
| 23 |
# 2οΈβ£ Send transcription as a prompt to ChatGPT
|
| 24 |
try:
|
| 25 |
response = client.chat.completions.create(
|
| 26 |
-
model="gpt-4o-mini",
|
| 27 |
messages=[
|
| 28 |
{"role": "system", "content": "You are a helpful assistant. Follow the user's instructions."},
|
| 29 |
{"role": "user", "content": chinese_text}
|
|
@@ -51,21 +51,40 @@ def audio_prompt_to_chatgpt(audio_path):
|
|
| 51 |
return chinese_text, chatgpt_reply_chinese, chatgpt_reply_english
|
| 52 |
|
| 53 |
# π Gradio UI
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
type="filepath",
|
| 59 |
label="ποΈ Speak Chinese or Upload Audio"
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
app.launch()
|
|
|
|
| 23 |
# 2οΈβ£ Send transcription as a prompt to ChatGPT
|
| 24 |
try:
|
| 25 |
response = client.chat.completions.create(
|
| 26 |
+
model="gpt-4o-mini",
|
| 27 |
messages=[
|
| 28 |
{"role": "system", "content": "You are a helpful assistant. Follow the user's instructions."},
|
| 29 |
{"role": "user", "content": chinese_text}
|
|
|
|
| 51 |
return chinese_text, chatgpt_reply_chinese, chatgpt_reply_english
|
| 52 |
|
| 53 |
# π Gradio UI
|
| 54 |
+
with gr.Blocks() as app:
|
| 55 |
+
gr.Markdown("### π€ Chinese Voice β ChatGPT Prompt with Copy Buttons")
|
| 56 |
+
|
| 57 |
+
audio_input = gr.Audio(
|
| 58 |
+
source="microphone",
|
| 59 |
type="filepath",
|
| 60 |
label="ποΈ Speak Chinese or Upload Audio"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
chinese_output = gr.Textbox(label="π€ ChatGPT Response (Chinese)")
|
| 64 |
+
english_output = gr.Textbox(label="π ChatGPT Response (English)")
|
| 65 |
+
|
| 66 |
+
submit_btn = gr.Button("Generate Response")
|
| 67 |
+
copy_chinese_btn = gr.Button("Copy Chinese Output")
|
| 68 |
+
copy_english_btn = gr.Button("Copy English Output")
|
| 69 |
+
|
| 70 |
+
# Connect submit button
|
| 71 |
+
submit_btn.click(
|
| 72 |
+
fn=audio_prompt_to_chatgpt,
|
| 73 |
+
inputs=audio_input,
|
| 74 |
+
outputs=[gr.Textbox(label="Chinese Prompt"), chinese_output, english_output]
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Connect copy buttons
|
| 78 |
+
copy_chinese_btn.click(
|
| 79 |
+
fn=lambda x: x,
|
| 80 |
+
inputs=chinese_output,
|
| 81 |
+
outputs=gr.Textbox(label="Copied Chinese")
|
| 82 |
+
)
|
| 83 |
+
copy_english_btn.click(
|
| 84 |
+
fn=lambda x: x,
|
| 85 |
+
inputs=english_output,
|
| 86 |
+
outputs=gr.Textbox(label="Copied English")
|
| 87 |
+
)
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
| 90 |
app.launch()
|