Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from openai import OpenAI
|
|
| 7 |
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
| 8 |
|
| 9 |
# π§ Load Whisper model once
|
| 10 |
-
whisper_model = whisper.load_model("
|
| 11 |
|
| 12 |
def audio_prompt_to_chatgpt(audio_path):
|
| 13 |
if audio_path is None:
|
|
@@ -51,40 +51,21 @@ 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 |
-
sources=["microphone", "upload"], # fixed: use sources instead of source
|
| 59 |
type="filepath",
|
| 60 |
label="ποΈ Speak Chinese or Upload Audio"
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 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()
|
|
|
|
| 7 |
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
| 8 |
|
| 9 |
# π§ Load Whisper model once
|
| 10 |
+
whisper_model = whisper.load_model("small")
|
| 11 |
|
| 12 |
def audio_prompt_to_chatgpt(audio_path):
|
| 13 |
if audio_path is None:
|
|
|
|
| 51 |
return chinese_text, chatgpt_reply_chinese, chatgpt_reply_english
|
| 52 |
|
| 53 |
# π Gradio UI
|
| 54 |
+
app = gr.Interface(
|
| 55 |
+
fn=audio_prompt_to_chatgpt,
|
| 56 |
+
inputs=gr.Audio(
|
| 57 |
+
sources=["microphone", "upload"], # microphone or upload
|
|
|
|
| 58 |
type="filepath",
|
| 59 |
label="ποΈ Speak Chinese or Upload Audio"
|
| 60 |
+
),
|
| 61 |
+
outputs=[
|
| 62 |
+
gr.Textbox(label="πΆ Transcribed Chinese Prompt"),
|
| 63 |
+
gr.Textbox(label="π€ ChatGPT Response (Chinese)"),
|
| 64 |
+
gr.Textbox(label="π ChatGPT Response (English)")
|
| 65 |
+
],
|
| 66 |
+
title="π€ Chinese Voice β ChatGPT Prompt with English",
|
| 67 |
+
description="Speak Chinese or upload audio. Whisper transcribes, ChatGPT executes your instruction, and the reply is shown in Chinese and English."
|
| 68 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
app.launch()
|