Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
7e4874e
1
Parent(s):
c4d5753
Upd ZeroGPU caller
Browse files- .gitignore +2 -1
- app.py +49 -50
.gitignore
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
local
|
| 2 |
*.json
|
| 3 |
-
.env*
|
|
|
|
|
|
| 1 |
local
|
| 2 |
*.json
|
| 3 |
+
.env*
|
| 4 |
+
gradio.py
|
app.py
CHANGED
|
@@ -252,6 +252,52 @@ def zero_gpu_probe():
|
|
| 252 |
"""
|
| 253 |
return "ready"
|
| 254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
# Create the enhanced Gradio interface
|
| 256 |
def create_interface():
|
| 257 |
"""Create an enhanced Gradio interface with proper layout"""
|
|
@@ -360,55 +406,8 @@ def create_interface():
|
|
| 360 |
- **GPU**: ZeroGPU powered
|
| 361 |
""")
|
| 362 |
|
| 363 |
-
# Event handlers
|
| 364 |
-
|
| 365 |
-
"""Handle transcription and update UI"""
|
| 366 |
-
if audio_file is None:
|
| 367 |
-
return (
|
| 368 |
-
"❌ Please upload an audio file first.",
|
| 369 |
-
"",
|
| 370 |
-
gr.update(visible=False),
|
| 371 |
-
gr.update(visible=False),
|
| 372 |
-
gr.update(visible=False),
|
| 373 |
-
gr.update(visible=False)
|
| 374 |
-
)
|
| 375 |
-
|
| 376 |
-
try:
|
| 377 |
-
# Initialize model if needed
|
| 378 |
-
initialize_model()
|
| 379 |
-
|
| 380 |
-
# Transcribe
|
| 381 |
-
result = transcribe_audio(audio_file)
|
| 382 |
-
|
| 383 |
-
if result.get("success"):
|
| 384 |
-
transcription_text = result["text"]
|
| 385 |
-
return (
|
| 386 |
-
f"✅ Transcription completed! ({len(transcription_text)} characters)",
|
| 387 |
-
transcription_text,
|
| 388 |
-
gr.update(visible=True, value=transcription_text),
|
| 389 |
-
gr.update(visible=True), # Show summarize button
|
| 390 |
-
gr.update(visible=False), # Hide summary output initially
|
| 391 |
-
gr.update(visible=True) # Show download button
|
| 392 |
-
)
|
| 393 |
-
else:
|
| 394 |
-
return (
|
| 395 |
-
f"❌ Error: {result.get('error', 'Unknown error')}",
|
| 396 |
-
"",
|
| 397 |
-
gr.update(visible=False),
|
| 398 |
-
gr.update(visible=False),
|
| 399 |
-
gr.update(visible=False),
|
| 400 |
-
gr.update(visible=False)
|
| 401 |
-
)
|
| 402 |
-
|
| 403 |
-
except Exception as e:
|
| 404 |
-
return (
|
| 405 |
-
f"❌ Unexpected error: {str(e)}",
|
| 406 |
-
"",
|
| 407 |
-
gr.update(visible=False),
|
| 408 |
-
gr.update(visible=False),
|
| 409 |
-
gr.update(visible=False),
|
| 410 |
-
gr.update(visible=False)
|
| 411 |
-
)
|
| 412 |
|
| 413 |
def summarize_content(transcription_text):
|
| 414 |
"""Summarize the transcription using Gemini"""
|
|
@@ -493,7 +492,7 @@ def create_interface():
|
|
| 493 |
|
| 494 |
# Connect events
|
| 495 |
transcribe_btn.click(
|
| 496 |
-
fn=
|
| 497 |
inputs=[audio_input],
|
| 498 |
outputs=[status_text, transcription_output, summarize_btn, summary_output, download_btn],
|
| 499 |
show_progress=True
|
|
|
|
| 252 |
"""
|
| 253 |
return "ready"
|
| 254 |
|
| 255 |
+
# GPU-bound handler for Gradio button; ensures ZeroGPU detects usage
|
| 256 |
+
@spaces.GPU
|
| 257 |
+
def handle_transcribe_gr(audio_file):
|
| 258 |
+
if audio_file is None:
|
| 259 |
+
return (
|
| 260 |
+
"❌ Please upload an audio file first.",
|
| 261 |
+
"",
|
| 262 |
+
gr.update(visible=False),
|
| 263 |
+
gr.update(visible=False),
|
| 264 |
+
gr.update(visible=False),
|
| 265 |
+
gr.update(visible=False)
|
| 266 |
+
)
|
| 267 |
+
try:
|
| 268 |
+
# Ensure pipeline is initialized
|
| 269 |
+
initialize_model()
|
| 270 |
+
print(f"[gradio] received filepath={audio_file}")
|
| 271 |
+
res = transcribe_audio(audio_file)
|
| 272 |
+
if res.get("success"):
|
| 273 |
+
txt = res["text"]
|
| 274 |
+
return (
|
| 275 |
+
f"✅ Transcription completed! ({len(txt)} characters)",
|
| 276 |
+
txt,
|
| 277 |
+
gr.update(visible=True, value=txt),
|
| 278 |
+
gr.update(visible=True), # show summarize button
|
| 279 |
+
gr.update(visible=False), # hide summary output initially
|
| 280 |
+
gr.update(visible=True) # show download button
|
| 281 |
+
)
|
| 282 |
+
return (
|
| 283 |
+
f"❌ Error: {res.get('error','Unknown error')}",
|
| 284 |
+
"",
|
| 285 |
+
gr.update(visible=False),
|
| 286 |
+
gr.update(visible=False),
|
| 287 |
+
gr.update(visible=False),
|
| 288 |
+
gr.update(visible=False)
|
| 289 |
+
)
|
| 290 |
+
except Exception as e:
|
| 291 |
+
print(f"[gradio] handle_transcribe_gr ERROR: {e}")
|
| 292 |
+
return (
|
| 293 |
+
f"❌ Unexpected error: {str(e)}",
|
| 294 |
+
"",
|
| 295 |
+
gr.update(visible=False),
|
| 296 |
+
gr.update(visible=False),
|
| 297 |
+
gr.update(visible=False),
|
| 298 |
+
gr.update(visible=False)
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
# Create the enhanced Gradio interface
|
| 302 |
def create_interface():
|
| 303 |
"""Create an enhanced Gradio interface with proper layout"""
|
|
|
|
| 406 |
- **GPU**: ZeroGPU powered
|
| 407 |
""")
|
| 408 |
|
| 409 |
+
# Event handlers (GPU-bound)
|
| 410 |
+
# (Handlers that run on GPU must be module-level functions to be detected by ZeroGPU)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
def summarize_content(transcription_text):
|
| 413 |
"""Summarize the transcription using Gemini"""
|
|
|
|
| 492 |
|
| 493 |
# Connect events
|
| 494 |
transcribe_btn.click(
|
| 495 |
+
fn=handle_transcribe_gr,
|
| 496 |
inputs=[audio_input],
|
| 497 |
outputs=[status_text, transcription_output, summarize_btn, summary_output, download_btn],
|
| 498 |
show_progress=True
|