Update app.py
Browse files
app.py
CHANGED
|
@@ -136,7 +136,6 @@ class UltimateVideoEvader:
|
|
| 136 |
return cmd, output_file
|
| 137 |
|
| 138 |
def process_video_background(self, job_id, input_path):
|
| 139 |
-
"""Background thread function with live logs"""
|
| 140 |
log_queue = jobs[job_id]["log_queue"]
|
| 141 |
|
| 142 |
def log(msg):
|
|
@@ -325,6 +324,16 @@ class UltimateVideoEvader:
|
|
| 325 |
})
|
| 326 |
job_list.sort(key=lambda x: x["timestamp"], reverse=True)
|
| 327 |
return job_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
|
| 330 |
# ========== Gradio Interface ==========
|
|
@@ -337,7 +346,6 @@ def create_interface():
|
|
| 337 |
**Live Logs में ETA, Speed, FPS और Progress की पूरी जानकारी देखें।**
|
| 338 |
""")
|
| 339 |
|
| 340 |
-
# Hidden state to store job_id
|
| 341 |
job_id_state = gr.State("")
|
| 342 |
|
| 343 |
with gr.Tab("📤 Upload & Process"):
|
|
@@ -365,14 +373,22 @@ def create_interface():
|
|
| 365 |
|
| 366 |
with gr.Tab("📜 Job History"):
|
| 367 |
gr.Markdown("### सभी Jobs की History")
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
# ===== Processing Functions =====
|
| 378 |
|
|
@@ -390,13 +406,6 @@ def create_interface():
|
|
| 390 |
progress = jobs.get(job_id, {}).get("progress", 0)
|
| 391 |
return logs, f"Status: {status} | Progress: {progress}%"
|
| 392 |
|
| 393 |
-
def refresh_full_status(job_id):
|
| 394 |
-
if not job_id or job_id not in jobs:
|
| 395 |
-
return "❌ No job", "", False
|
| 396 |
-
status_text, output_file, status = evader.get_job_status(job_id)
|
| 397 |
-
download_visible = status == "completed" and output_file
|
| 398 |
-
return status_text, gr.update(visible=bool(download_visible))
|
| 399 |
-
|
| 400 |
def download_completed(job_id):
|
| 401 |
if not job_id or job_id not in jobs:
|
| 402 |
return None
|
|
@@ -412,27 +421,27 @@ def create_interface():
|
|
| 412 |
|
| 413 |
rows = []
|
| 414 |
for j in job_list:
|
| 415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
rows.append([
|
| 417 |
j["job_id"],
|
| 418 |
j["input_file"],
|
| 419 |
-
|
| 420 |
j["timestamp"],
|
| 421 |
-
f"{j['progress']}%"
|
| 422 |
-
download_link
|
| 423 |
])
|
| 424 |
return gr.update(value=rows, visible=True)
|
| 425 |
|
| 426 |
-
def
|
| 427 |
-
if not
|
| 428 |
-
return None
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
job_id = history_data[row_idx][0]
|
| 432 |
-
job = jobs.get(job_id)
|
| 433 |
-
if job and job.get("status") == "completed" and job.get("output_file"):
|
| 434 |
-
return job["output_file"]
|
| 435 |
-
return None
|
| 436 |
|
| 437 |
# ===== Event Handlers =====
|
| 438 |
|
|
@@ -464,13 +473,13 @@ def create_interface():
|
|
| 464 |
outputs=[job_history]
|
| 465 |
)
|
| 466 |
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
inputs=[
|
| 470 |
-
outputs=[
|
| 471 |
)
|
| 472 |
|
| 473 |
-
# ===== Auto-refresh using gr.Timer
|
| 474 |
timer = gr.Timer(value=5, active=False)
|
| 475 |
|
| 476 |
def toggle_timer(job_id):
|
|
@@ -478,14 +487,12 @@ def create_interface():
|
|
| 478 |
return gr.update(active=True)
|
| 479 |
return gr.update(active=False)
|
| 480 |
|
| 481 |
-
# Start timer when job starts
|
| 482 |
process_btn.click(
|
| 483 |
toggle_timer,
|
| 484 |
inputs=[job_id_state],
|
| 485 |
outputs=[timer]
|
| 486 |
)
|
| 487 |
|
| 488 |
-
# Timer ticks refresh logs
|
| 489 |
timer.tick(
|
| 490 |
refresh_logs,
|
| 491 |
inputs=[job_id_state],
|
|
|
|
| 136 |
return cmd, output_file
|
| 137 |
|
| 138 |
def process_video_background(self, job_id, input_path):
|
|
|
|
| 139 |
log_queue = jobs[job_id]["log_queue"]
|
| 140 |
|
| 141 |
def log(msg):
|
|
|
|
| 324 |
})
|
| 325 |
job_list.sort(key=lambda x: x["timestamp"], reverse=True)
|
| 326 |
return job_list
|
| 327 |
+
|
| 328 |
+
def download_job_by_id(self, job_id):
|
| 329 |
+
if job_id not in jobs:
|
| 330 |
+
return None, "❌ Job ID not found"
|
| 331 |
+
job = jobs[job_id]
|
| 332 |
+
if job.get("status") != "completed":
|
| 333 |
+
return None, f"⏳ Job is {job.get('status')} – not ready yet"
|
| 334 |
+
if not job.get("output_file") or not os.path.exists(job.get("output_file")):
|
| 335 |
+
return None, "❌ Output file missing"
|
| 336 |
+
return job["output_file"], f"✅ Download ready: {os.path.basename(job['output_file'])}"
|
| 337 |
|
| 338 |
|
| 339 |
# ========== Gradio Interface ==========
|
|
|
|
| 346 |
**Live Logs में ETA, Speed, FPS और Progress की पूरी जानकारी देखें।**
|
| 347 |
""")
|
| 348 |
|
|
|
|
| 349 |
job_id_state = gr.State("")
|
| 350 |
|
| 351 |
with gr.Tab("📤 Upload & Process"):
|
|
|
|
| 373 |
|
| 374 |
with gr.Tab("📜 Job History"):
|
| 375 |
gr.Markdown("### सभी Jobs की History")
|
| 376 |
+
|
| 377 |
+
with gr.Row():
|
| 378 |
+
with gr.Column(scale=2):
|
| 379 |
+
history_refresh_btn = gr.Button("🔄 Refresh History")
|
| 380 |
+
job_history = gr.Dataframe(
|
| 381 |
+
headers=["Job ID", "Input File", "Status", "Timestamp", "Progress"],
|
| 382 |
+
datatype=["str", "str", "str", "str", "str"],
|
| 383 |
+
label="Job History",
|
| 384 |
+
interactive=False
|
| 385 |
+
)
|
| 386 |
+
with gr.Column(scale=1):
|
| 387 |
+
gr.Markdown("### 📥 Download by Job ID")
|
| 388 |
+
download_job_id = gr.Textbox(label="Enter Job ID", placeholder="e.g., 5b7c3970")
|
| 389 |
+
download_by_id_btn = gr.Button("📥 Download Video", variant="primary")
|
| 390 |
+
download_by_id_output = gr.File(label="Download", visible=False)
|
| 391 |
+
download_by_id_status = gr.Textbox(label="Status", lines=2, interactive=False)
|
| 392 |
|
| 393 |
# ===== Processing Functions =====
|
| 394 |
|
|
|
|
| 406 |
progress = jobs.get(job_id, {}).get("progress", 0)
|
| 407 |
return logs, f"Status: {status} | Progress: {progress}%"
|
| 408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
def download_completed(job_id):
|
| 410 |
if not job_id or job_id not in jobs:
|
| 411 |
return None
|
|
|
|
| 421 |
|
| 422 |
rows = []
|
| 423 |
for j in job_list:
|
| 424 |
+
status_display = j["status"]
|
| 425 |
+
if j["status"] == "completed":
|
| 426 |
+
status_display = "✅ completed"
|
| 427 |
+
elif j["status"] == "processing":
|
| 428 |
+
status_display = "⏳ processing"
|
| 429 |
+
elif j["status"] == "failed":
|
| 430 |
+
status_display = "❌ failed"
|
| 431 |
rows.append([
|
| 432 |
j["job_id"],
|
| 433 |
j["input_file"],
|
| 434 |
+
status_display,
|
| 435 |
j["timestamp"],
|
| 436 |
+
f"{j['progress']}%"
|
|
|
|
| 437 |
])
|
| 438 |
return gr.update(value=rows, visible=True)
|
| 439 |
|
| 440 |
+
def download_by_job_id(job_id):
|
| 441 |
+
if not job_id:
|
| 442 |
+
return None, "❌ Please enter a Job ID"
|
| 443 |
+
file_path, status = evader.download_job_by_id(job_id)
|
| 444 |
+
return file_path, status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
|
| 446 |
# ===== Event Handlers =====
|
| 447 |
|
|
|
|
| 473 |
outputs=[job_history]
|
| 474 |
)
|
| 475 |
|
| 476 |
+
download_by_id_btn.click(
|
| 477 |
+
download_by_job_id,
|
| 478 |
+
inputs=[download_job_id],
|
| 479 |
+
outputs=[download_by_id_output, download_by_id_status]
|
| 480 |
)
|
| 481 |
|
| 482 |
+
# ===== Auto-refresh using gr.Timer =====
|
| 483 |
timer = gr.Timer(value=5, active=False)
|
| 484 |
|
| 485 |
def toggle_timer(job_id):
|
|
|
|
| 487 |
return gr.update(active=True)
|
| 488 |
return gr.update(active=False)
|
| 489 |
|
|
|
|
| 490 |
process_btn.click(
|
| 491 |
toggle_timer,
|
| 492 |
inputs=[job_id_state],
|
| 493 |
outputs=[timer]
|
| 494 |
)
|
| 495 |
|
|
|
|
| 496 |
timer.tick(
|
| 497 |
refresh_logs,
|
| 498 |
inputs=[job_id_state],
|