shiue2000 commited on
Commit
ff98e3b
Β·
verified Β·
1 Parent(s): 2995523

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -14
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", # or gpt-4o for higher quality
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
- app = gr.Interface(
55
- fn=audio_prompt_to_chatgpt,
56
- inputs=gr.Audio(
57
- sources=["microphone", "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()
 
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()