shiue2000 commited on
Commit
9b0a1ac
Β·
verified Β·
1 Parent(s): f69690a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -33
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("base")
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
- with gr.Blocks() as app:
55
- gr.Markdown("### 🎀 Chinese Voice β†’ ChatGPT Prompt with Copy Buttons")
56
-
57
- audio_input = gr.Audio(
58
- sources=["microphone", "upload"], # fixed: use sources instead of source
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()
 
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()