shiue2000 commited on
Commit
2df333c
Β·
verified Β·
1 Parent(s): 8bde116

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -11,14 +11,14 @@ whisper_model = whisper.load_model("small")
11
 
12
  def audio_prompt_to_chatgpt(audio_path):
13
  if audio_path is None:
14
- return "", "", ""
15
 
16
  # 1️⃣ Transcribe audio β†’ Chinese text
17
  result = whisper_model.transcribe(audio_path, language="zh")
18
  chinese_text = result.get("text", "").strip()
19
 
20
  if not chinese_text:
21
- return "⚠️ Could not transcribe audio.", "", ""
22
 
23
  # 2️⃣ ChatGPT reply in Chinese
24
  try:
@@ -48,7 +48,14 @@ def audio_prompt_to_chatgpt(audio_path):
48
  except Exception as e:
49
  chatgpt_reply_english = f"⚠️ Translation failed: {e}"
50
 
51
- return chatgpt_reply_chinese, chatgpt_reply_english, chinese_text
 
 
 
 
 
 
 
52
 
53
  # πŸš€ Gradio UI
54
  with gr.Blocks() as app:
@@ -60,28 +67,20 @@ with gr.Blocks() as app:
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
- transcription_output = gr.Textbox(label="🈢 Transcribed Chinese Prompt")
 
 
66
 
67
  submit_btn = gr.Button("Generate Response")
68
 
69
- # Copy buttons
70
- copy_chinese_btn = gr.Button("Copy Chinese")
71
- copy_english_btn = gr.Button("Copy English")
72
- copy_transcription_btn = gr.Button("Copy Transcription")
73
-
74
  # Connect submit button
75
  submit_btn.click(
76
  fn=audio_prompt_to_chatgpt,
77
  inputs=audio_input,
78
- outputs=[chinese_output, english_output, transcription_output]
79
  )
80
 
81
- # Connect copy buttons to copy respective outputs
82
- copy_chinese_btn.click(lambda x: x, inputs=chinese_output, outputs=chinese_output)
83
- copy_english_btn.click(lambda x: x, inputs=english_output, outputs=english_output)
84
- copy_transcription_btn.click(lambda x: x, inputs=transcription_output, outputs=transcription_output)
85
-
86
  if __name__ == "__main__":
87
  app.launch()
 
11
 
12
  def audio_prompt_to_chatgpt(audio_path):
13
  if audio_path is None:
14
+ return ""
15
 
16
  # 1️⃣ Transcribe audio β†’ Chinese text
17
  result = whisper_model.transcribe(audio_path, language="zh")
18
  chinese_text = result.get("text", "").strip()
19
 
20
  if not chinese_text:
21
+ return "⚠️ Could not transcribe audio."
22
 
23
  # 2️⃣ ChatGPT reply in Chinese
24
  try:
 
48
  except Exception as e:
49
  chatgpt_reply_english = f"⚠️ Translation failed: {e}"
50
 
51
+ # Combine everything in one cell
52
+ combined_output = (
53
+ f"🈢 **Transcribed Chinese Prompt:**\n{chinese_text}\n\n"
54
+ f"πŸ€– **ChatGPT Response (Chinese):**\n{chatgpt_reply_chinese}\n\n"
55
+ f"🌍 **ChatGPT Response (English):**\n{chatgpt_reply_english}"
56
+ )
57
+
58
+ return combined_output
59
 
60
  # πŸš€ Gradio UI
61
  with gr.Blocks() as app:
 
67
  label="πŸŽ™οΈ Speak Chinese or Upload Audio"
68
  )
69
 
70
+ output_box = gr.Textbox(
71
+ label="πŸ“‹ Results (Copy Friendly)",
72
+ lines=15,
73
+ interactive=False
74
+ )
75
 
76
  submit_btn = gr.Button("Generate Response")
77
 
 
 
 
 
 
78
  # Connect submit button
79
  submit_btn.click(
80
  fn=audio_prompt_to_chatgpt,
81
  inputs=audio_input,
82
+ outputs=output_box
83
  )
84
 
 
 
 
 
 
85
  if __name__ == "__main__":
86
  app.launch()