Update app.py
Browse filesfirst attempt text or audio input
app.py
CHANGED
|
@@ -313,17 +313,25 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 313 |
login_message = gr.Markdown()
|
| 314 |
|
| 315 |
with gr.Column(visible=False) as main_interface:
|
| 316 |
-
gr.Markdown("Record audio, transcribe it, and optionally generate text based on the
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|
| 326 |
-
|
| 327 |
with gr.Row():
|
| 328 |
audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
|
| 329 |
save_msg = gr.Textbox(label="Save Status")
|
|
@@ -339,7 +347,8 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 339 |
generate_btn = gr.Button("Generate Text")
|
| 340 |
|
| 341 |
generated_text_output = gr.Textbox(label="Generated Text", show_copy_button=True)
|
| 342 |
-
|
|
|
|
| 343 |
save_btn.click(
|
| 344 |
save_audio,
|
| 345 |
inputs=[audio_input],
|
|
@@ -362,11 +371,20 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 362 |
save_transcribe_fix,
|
| 363 |
inputs=[audio_input, prompt_type],
|
| 364 |
outputs=[audio_output, transcription_output, generated_text_output]
|
| 365 |
-
)
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
generate_btn.click(
|
| 368 |
-
|
| 369 |
-
inputs=[
|
| 370 |
outputs=[generated_text_output]
|
| 371 |
)
|
| 372 |
|
|
@@ -388,7 +406,5 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 388 |
outputs=[main_interface, login_message]
|
| 389 |
)
|
| 390 |
|
| 391 |
-
# Launch the interface
|
| 392 |
demo.launch()
|
| 393 |
-
|
| 394 |
|
|
|
|
| 313 |
login_message = gr.Markdown()
|
| 314 |
|
| 315 |
with gr.Column(visible=False) as main_interface:
|
| 316 |
+
gr.Markdown("Record audio, transcribe it, or enter text manually, and optionally generate text based on the input.")
|
| 317 |
+
|
| 318 |
+
input_toggle = gr.Checkbox(label="Use Manual Text Input Instead of Audio", value=False)
|
| 319 |
+
|
| 320 |
+
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Record or Upload Audio", visible=True)
|
| 321 |
+
text_input = gr.Textbox(label="Enter Text Manually", visible=False)
|
| 322 |
+
|
| 323 |
+
input_toggle.change(
|
| 324 |
+
lambda use_text: (gr.update(visible=not use_text), gr.update(visible=use_text)),
|
| 325 |
+
inputs=[input_toggle],
|
| 326 |
+
outputs=[audio_input, text_input]
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
with gr.Row():
|
| 330 |
save_btn = gr.Button("Save Audio")
|
| 331 |
transcribe_btn = gr.Button("Transcribe Audio")
|
| 332 |
transcribe_fix_btn = gr.Button("Transcribe & Fix")
|
| 333 |
+
save_transcribe_fix_btn = gr.Button("Save, Transcribe & Fix")
|
| 334 |
+
|
| 335 |
with gr.Row():
|
| 336 |
audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
|
| 337 |
save_msg = gr.Textbox(label="Save Status")
|
|
|
|
| 347 |
generate_btn = gr.Button("Generate Text")
|
| 348 |
|
| 349 |
generated_text_output = gr.Textbox(label="Generated Text", show_copy_button=True)
|
| 350 |
+
|
| 351 |
+
# Actions for audio-related inputs
|
| 352 |
save_btn.click(
|
| 353 |
save_audio,
|
| 354 |
inputs=[audio_input],
|
|
|
|
| 371 |
save_transcribe_fix,
|
| 372 |
inputs=[audio_input, prompt_type],
|
| 373 |
outputs=[audio_output, transcription_output, generated_text_output]
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
# Automatically detect if text or audio should be used
|
| 377 |
+
def determine_input(audio, text, prompt):
|
| 378 |
+
if text.strip(): # If text is entered, use it
|
| 379 |
+
return generate_text(text, prompt)
|
| 380 |
+
elif audio: # Otherwise, check if audio exists and use it
|
| 381 |
+
return generate_text(transcription_output.value, prompt)
|
| 382 |
+
else:
|
| 383 |
+
return "Please provide either text or audio."
|
| 384 |
+
|
| 385 |
generate_btn.click(
|
| 386 |
+
determine_input,
|
| 387 |
+
inputs=[audio_input, text_input, prompt_type],
|
| 388 |
outputs=[generated_text_output]
|
| 389 |
)
|
| 390 |
|
|
|
|
| 406 |
outputs=[main_interface, login_message]
|
| 407 |
)
|
| 408 |
|
|
|
|
| 409 |
demo.launch()
|
|
|
|
| 410 |
|