bai4578 commited on
Commit
87f80fb
·
verified ·
1 Parent(s): cf52bc2

Update app.py

Browse files

first attempt at combining save-transcribe-fix single click

Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  from pydub import AudioSegment
7
 
8
  # Initialize the Groq client
9
- client = Groq(api_key=os.environ["keko"])
10
 
11
 
12
 
@@ -284,10 +284,26 @@ def transcribe_and_generate(audio_file, prompt_type):
284
 
285
  return transcription, generated_text
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
 
288
  # ------------------------------------------------
289
  # Create the Gradio interface using Blocks
290
  # -------------------------------------------------
 
291
  with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
292
  gr.Markdown("# Audio Recorder, Transcriber, and Text Generator")
293
  gr.Markdown("Enter the correct password to access the application.")
@@ -305,7 +321,8 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
305
  with gr.Row():
306
  save_btn = gr.Button("Save Audio")
307
  transcribe_btn = gr.Button("Transcribe Audio")
308
- transcribe_fix_btn = gr.Button("Transcribe & Fix") # New button
 
309
 
310
  with gr.Row():
311
  audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
@@ -340,6 +357,12 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
340
  inputs=[audio_input, prompt_type],
341
  outputs=[transcription_output, generated_text_output]
342
  )
 
 
 
 
 
 
343
 
344
  generate_btn.click(
345
  generate_text,
@@ -366,6 +389,6 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
366
  )
367
 
368
  # Launch the interface
369
- demo.launch()
370
 
371
 
 
6
  from pydub import AudioSegment
7
 
8
  # Initialize the Groq client
9
+ client = Groq(api_key=os.environ["keko"])
10
 
11
 
12
 
 
284
 
285
  return transcription, generated_text
286
 
287
+ # Define a new function that combines save, transcribe, and fix
288
+ def save_transcribe_fix(audio_file, prompt_type):
289
+ # Step 1: Save the audio
290
+ saved_audio, save_status = save_audio(audio_file)
291
+ if not saved_audio:
292
+ return None, save_status, None # Return error message if saving fails
293
+
294
+ # Step 2: Transcribe the audio
295
+ transcription = transcribe_audio(saved_audio)
296
+
297
+ # Step 3: Generate the fixed text
298
+ fixed_text = generate_text(transcription, prompt_type)
299
+
300
+ return saved_audio, transcription, fixed_text
301
+
302
 
303
  # ------------------------------------------------
304
  # Create the Gradio interface using Blocks
305
  # -------------------------------------------------
306
+ # Update Gradio UI with a new button
307
  with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
308
  gr.Markdown("# Audio Recorder, Transcriber, and Text Generator")
309
  gr.Markdown("Enter the correct password to access the application.")
 
321
  with gr.Row():
322
  save_btn = gr.Button("Save Audio")
323
  transcribe_btn = gr.Button("Transcribe Audio")
324
+ transcribe_fix_btn = gr.Button("Transcribe & Fix")
325
+ save_transcribe_fix_btn = gr.Button("Save, Transcribe & Fix") # New button
326
 
327
  with gr.Row():
328
  audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
 
357
  inputs=[audio_input, prompt_type],
358
  outputs=[transcription_output, generated_text_output]
359
  )
360
+
361
+ save_transcribe_fix_btn.click(
362
+ save_transcribe_fix,
363
+ inputs=[audio_input, prompt_type],
364
+ outputs=[audio_output, transcription_output, generated_text_output]
365
+ ) # New button action
366
 
367
  generate_btn.click(
368
  generate_text,
 
389
  )
390
 
391
  # Launch the interface
392
+ demo.launch()
393
 
394