Update app.py
Browse filescombine button attempt (transcribe+fix)
app.py
CHANGED
|
@@ -236,7 +236,7 @@ def transcribe_audio(audio_file):
|
|
| 236 |
transcription = client.audio.transcriptions.create(
|
| 237 |
file=(f"chunk_{i}.mp3", file.read()),
|
| 238 |
model="whisper-large-v3",
|
| 239 |
-
prompt="fix this dictated Text contains gastroenterology terms.
|
| 240 |
response_format="json",
|
| 241 |
temperature=0.0
|
| 242 |
)
|
|
@@ -253,7 +253,7 @@ def generate_text(text, prompt_type):
|
|
| 253 |
return "No text provided."
|
| 254 |
|
| 255 |
prompts = {
|
| 256 |
-
"dic_clean":"this is a dictated text, domain is gastroenterology. correct the text while maintain the tone and style but correct spelling and replace punctuation and newline wordings, follow inline corrections as dictated by the user (eg delete, replace, etc...).",
|
| 257 |
"summarize": "You are an AI assistant specialized in summarizing text. Provide a concise summary of the given text.",
|
| 258 |
"create_qa": "You are an AI assistant specialized in creating Q&A pairs. Generate relevant questions and answers based on the given text.",
|
| 259 |
"analyze": "You are an AI assistant specialized in text analysis. Analyze the main points and key ideas of the given text."
|
|
@@ -274,10 +274,20 @@ def generate_text(text, prompt_type):
|
|
| 274 |
return response.choices[0].message.content
|
| 275 |
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
|
| 279 |
-
|
| 280 |
# Create the Gradio interface using Blocks
|
|
|
|
| 281 |
with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
| 282 |
gr.Markdown("# Audio Recorder, Transcriber, and Text Generator")
|
| 283 |
gr.Markdown("Enter the correct password to access the application.")
|
|
@@ -295,6 +305,7 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 295 |
with gr.Row():
|
| 296 |
save_btn = gr.Button("Save Audio")
|
| 297 |
transcribe_btn = gr.Button("Transcribe Audio")
|
|
|
|
| 298 |
|
| 299 |
with gr.Row():
|
| 300 |
audio_output = gr.Audio(label="Saved Audio (MP3)", format="mp3")
|
|
@@ -304,7 +315,7 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 304 |
|
| 305 |
with gr.Row():
|
| 306 |
prompt_type = gr.Dropdown(
|
| 307 |
-
choices=["dic_clean","summarize", "create_qa", "analyze"],
|
| 308 |
label="Select Text Generation Type",
|
| 309 |
value="dic_clean"
|
| 310 |
)
|
|
@@ -324,6 +335,12 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
|
|
| 324 |
outputs=[transcription_output]
|
| 325 |
)
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
generate_btn.click(
|
| 328 |
generate_text,
|
| 329 |
inputs=[transcription_output, prompt_type],
|
|
|
|
| 236 |
transcription = client.audio.transcriptions.create(
|
| 237 |
file=(f"chunk_{i}.mp3", file.read()),
|
| 238 |
model="whisper-large-v3",
|
| 239 |
+
prompt="fix this dictated Text contains gastroenterology terms. ",
|
| 240 |
response_format="json",
|
| 241 |
temperature=0.0
|
| 242 |
)
|
|
|
|
| 253 |
return "No text provided."
|
| 254 |
|
| 255 |
prompts = {
|
| 256 |
+
"dic_clean":"this is a dictated text, domain is likely medical/gastroenterology. correct the text while maintain the tone and style but correct spelling and replace punctuation and newline wordings, follow inline corrections as dictated by the user (eg delete, replace, etc...).",
|
| 257 |
"summarize": "You are an AI assistant specialized in summarizing text. Provide a concise summary of the given text.",
|
| 258 |
"create_qa": "You are an AI assistant specialized in creating Q&A pairs. Generate relevant questions and answers based on the given text.",
|
| 259 |
"analyze": "You are an AI assistant specialized in text analysis. Analyze the main points and key ideas of the given text."
|
|
|
|
| 274 |
return response.choices[0].message.content
|
| 275 |
|
| 276 |
|
| 277 |
+
# Define the new function for "Transcribe & Fix"
|
| 278 |
+
def transcribe_and_generate(audio_file, prompt_type):
|
| 279 |
+
# Transcribe the audio
|
| 280 |
+
transcription = transcribe_audio(audio_file)
|
| 281 |
+
|
| 282 |
+
# Generate the text based on the transcription and selected prompt
|
| 283 |
+
generated_text = generate_text(transcription, 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 |
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")
|
|
|
|
| 315 |
|
| 316 |
with gr.Row():
|
| 317 |
prompt_type = gr.Dropdown(
|
| 318 |
+
choices=["dic_clean", "summarize", "create_qa", "analyze"],
|
| 319 |
label="Select Text Generation Type",
|
| 320 |
value="dic_clean"
|
| 321 |
)
|
|
|
|
| 335 |
outputs=[transcription_output]
|
| 336 |
)
|
| 337 |
|
| 338 |
+
transcribe_fix_btn.click(
|
| 339 |
+
transcribe_and_generate,
|
| 340 |
+
inputs=[audio_input, prompt_type],
|
| 341 |
+
outputs=[transcription_output, generated_text_output]
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
generate_btn.click(
|
| 345 |
generate_text,
|
| 346 |
inputs=[transcription_output, prompt_type],
|