Spaces:
Runtime error
Runtime error
nice - downloads too
Browse files- .gitignore +2 -1
- app.py +52 -18
.gitignore
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
.venv/
|
| 2 |
transcripts/
|
| 3 |
-
temp_audio/
|
|
|
|
|
|
| 1 |
.venv/
|
| 2 |
transcripts/
|
| 3 |
+
temp_audio/
|
| 4 |
+
temp_downloads/
|
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from pydub import AudioSegment
|
|
| 11 |
import asyncio
|
| 12 |
import io
|
| 13 |
from itertools import groupby
|
|
|
|
| 14 |
|
| 15 |
prompt = '''
|
| 16 |
You are an expert transcript editor. Your task is to enhance this transcript for maximum readability while maintaining the core message.
|
|
@@ -256,6 +257,23 @@ def rename_speakers(text: str, speaker_map: dict) -> str:
|
|
| 256 |
return result
|
| 257 |
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
def process_audio(audio_file):
|
| 260 |
try:
|
| 261 |
temp_path = Path("temp_audio")
|
|
@@ -266,11 +284,12 @@ def process_audio(audio_file):
|
|
| 266 |
with open(temp_file, "wb") as f:
|
| 267 |
f.write(audio_file)
|
| 268 |
|
| 269 |
-
# Initial state -
|
| 270 |
yield (
|
| 271 |
gr.update(value="", visible=True), # original transcript
|
| 272 |
gr.update(value="", visible=True), # enhanced transcript
|
| 273 |
-
|
|
|
|
| 274 |
)
|
| 275 |
|
| 276 |
# Get transcript
|
|
@@ -279,11 +298,15 @@ def process_audio(audio_file):
|
|
| 279 |
dialogues = list(group_utterances_by_speaker(utterances))
|
| 280 |
original = format_chunk(dialogues, markdown=True)
|
| 281 |
|
| 282 |
-
#
|
|
|
|
|
|
|
|
|
|
| 283 |
yield (
|
| 284 |
gr.update(value=original, visible=True),
|
| 285 |
gr.update(value="", visible=True),
|
| 286 |
-
|
|
|
|
| 287 |
)
|
| 288 |
|
| 289 |
try:
|
|
@@ -293,21 +316,27 @@ def process_audio(audio_file):
|
|
| 293 |
merged = "\n\n".join(chunk.strip() for chunk in enhanced)
|
| 294 |
merged = apply_markdown_formatting(merged)
|
| 295 |
|
|
|
|
|
|
|
|
|
|
| 296 |
# Show final result
|
| 297 |
yield (
|
| 298 |
gr.update(value=original, visible=True),
|
| 299 |
gr.update(value=merged, visible=True),
|
| 300 |
-
|
|
|
|
| 301 |
)
|
| 302 |
|
| 303 |
except Exception as e:
|
| 304 |
yield (
|
| 305 |
gr.update(value=original, visible=True),
|
| 306 |
gr.update(value=f"Error: {str(e)}", visible=True),
|
| 307 |
-
|
|
|
|
| 308 |
)
|
| 309 |
|
| 310 |
finally:
|
|
|
|
| 311 |
if os.path.exists(temp_file):
|
| 312 |
os.remove(temp_file)
|
| 313 |
|
|
@@ -342,36 +371,41 @@ with gr.Blocks(title="Transcript Enhancer") as demo:
|
|
| 342 |
with gr.Row():
|
| 343 |
with gr.Column():
|
| 344 |
gr.Markdown("### Original Transcript")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
original_output = gr.Markdown()
|
| 346 |
|
| 347 |
with gr.Column():
|
| 348 |
gr.Markdown("### Enhanced Transcript")
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
| 352 |
)
|
| 353 |
enhanced_output = gr.Markdown()
|
| 354 |
|
| 355 |
-
# Add some CSS
|
| 356 |
gr.Markdown("""
|
| 357 |
<style>
|
| 358 |
-
.
|
| 359 |
-
|
| 360 |
-
border-radius: 4px;
|
| 361 |
-
background-color: #f0f0f0;
|
| 362 |
-
margin-bottom: 10px;
|
| 363 |
-
display: inline-block;
|
| 364 |
}
|
| 365 |
</style>
|
| 366 |
""")
|
| 367 |
-
|
| 368 |
transcribe_btn.click(
|
| 369 |
fn=process_audio,
|
| 370 |
inputs=[audio_input],
|
| 371 |
outputs=[
|
| 372 |
original_output,
|
| 373 |
enhanced_output,
|
| 374 |
-
|
|
|
|
| 375 |
]
|
| 376 |
)
|
| 377 |
|
|
|
|
| 11 |
import asyncio
|
| 12 |
import io
|
| 13 |
from itertools import groupby
|
| 14 |
+
from datetime import datetime
|
| 15 |
|
| 16 |
prompt = '''
|
| 17 |
You are an expert transcript editor. Your task is to enhance this transcript for maximum readability while maintaining the core message.
|
|
|
|
| 257 |
return result
|
| 258 |
|
| 259 |
|
| 260 |
+
def create_downloadable_file(content: str, prefix: str) -> str:
|
| 261 |
+
"""Create a temporary file with the content and return filepath"""
|
| 262 |
+
temp_dir = Path("temp_downloads")
|
| 263 |
+
temp_dir.mkdir(exist_ok=True)
|
| 264 |
+
|
| 265 |
+
# Create a unique filename
|
| 266 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 267 |
+
filename = f"{prefix}_{timestamp}.md"
|
| 268 |
+
filepath = temp_dir / filename
|
| 269 |
+
|
| 270 |
+
# Write content to file
|
| 271 |
+
with open(filepath, "w", encoding="utf-8") as f:
|
| 272 |
+
f.write(content)
|
| 273 |
+
|
| 274 |
+
return str(filepath)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
def process_audio(audio_file):
|
| 278 |
try:
|
| 279 |
temp_path = Path("temp_audio")
|
|
|
|
| 284 |
with open(temp_file, "wb") as f:
|
| 285 |
f.write(audio_file)
|
| 286 |
|
| 287 |
+
# Initial state - clear both transcripts
|
| 288 |
yield (
|
| 289 |
gr.update(value="", visible=True), # original transcript
|
| 290 |
gr.update(value="", visible=True), # enhanced transcript
|
| 291 |
+
None, # original download
|
| 292 |
+
None, # enhanced download
|
| 293 |
)
|
| 294 |
|
| 295 |
# Get transcript
|
|
|
|
| 298 |
dialogues = list(group_utterances_by_speaker(utterances))
|
| 299 |
original = format_chunk(dialogues, markdown=True)
|
| 300 |
|
| 301 |
+
# Create downloadable file for original transcript
|
| 302 |
+
original_file = create_downloadable_file(original, "original_transcript")
|
| 303 |
+
|
| 304 |
+
# Show original transcript
|
| 305 |
yield (
|
| 306 |
gr.update(value=original, visible=True),
|
| 307 |
gr.update(value="", visible=True),
|
| 308 |
+
original_file,
|
| 309 |
+
None,
|
| 310 |
)
|
| 311 |
|
| 312 |
try:
|
|
|
|
| 316 |
merged = "\n\n".join(chunk.strip() for chunk in enhanced)
|
| 317 |
merged = apply_markdown_formatting(merged)
|
| 318 |
|
| 319 |
+
# Create downloadable file for enhanced transcript
|
| 320 |
+
enhanced_file = create_downloadable_file(merged, "enhanced_transcript")
|
| 321 |
+
|
| 322 |
# Show final result
|
| 323 |
yield (
|
| 324 |
gr.update(value=original, visible=True),
|
| 325 |
gr.update(value=merged, visible=True),
|
| 326 |
+
original_file,
|
| 327 |
+
enhanced_file,
|
| 328 |
)
|
| 329 |
|
| 330 |
except Exception as e:
|
| 331 |
yield (
|
| 332 |
gr.update(value=original, visible=True),
|
| 333 |
gr.update(value=f"Error: {str(e)}", visible=True),
|
| 334 |
+
original_file,
|
| 335 |
+
None,
|
| 336 |
)
|
| 337 |
|
| 338 |
finally:
|
| 339 |
+
# Cleanup temp files
|
| 340 |
if os.path.exists(temp_file):
|
| 341 |
os.remove(temp_file)
|
| 342 |
|
|
|
|
| 371 |
with gr.Row():
|
| 372 |
with gr.Column():
|
| 373 |
gr.Markdown("### Original Transcript")
|
| 374 |
+
original_download = gr.File(
|
| 375 |
+
label="Download as Markdown",
|
| 376 |
+
file_count="single",
|
| 377 |
+
visible=True,
|
| 378 |
+
interactive=False,
|
| 379 |
+
)
|
| 380 |
original_output = gr.Markdown()
|
| 381 |
|
| 382 |
with gr.Column():
|
| 383 |
gr.Markdown("### Enhanced Transcript")
|
| 384 |
+
enhanced_download = gr.File(
|
| 385 |
+
label="Download as Markdown",
|
| 386 |
+
file_count="single",
|
| 387 |
+
visible=True,
|
| 388 |
+
interactive=False,
|
| 389 |
)
|
| 390 |
enhanced_output = gr.Markdown()
|
| 391 |
|
| 392 |
+
# Add some CSS to style the download buttons
|
| 393 |
gr.Markdown("""
|
| 394 |
<style>
|
| 395 |
+
.download-button {
|
| 396 |
+
margin-top: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
}
|
| 398 |
</style>
|
| 399 |
""")
|
| 400 |
+
|
| 401 |
transcribe_btn.click(
|
| 402 |
fn=process_audio,
|
| 403 |
inputs=[audio_input],
|
| 404 |
outputs=[
|
| 405 |
original_output,
|
| 406 |
enhanced_output,
|
| 407 |
+
original_download,
|
| 408 |
+
enhanced_download
|
| 409 |
]
|
| 410 |
)
|
| 411 |
|