Spaces:
Running
Running
progress bar removed
Browse files
app.py
CHANGED
|
@@ -23,12 +23,11 @@ def _process_job_worker(job_id, work_dir, source_path, target_path, source_lang,
|
|
| 23 |
|
| 24 |
status_file.write_text("processing")
|
| 25 |
|
| 26 |
-
def progress_callback(
|
| 27 |
data = {
|
| 28 |
-
"
|
| 29 |
"step": step,
|
| 30 |
"total": total,
|
| 31 |
-
"message": message,
|
| 32 |
"timestamp": time.time()
|
| 33 |
}
|
| 34 |
with open(progress_file, "w") as f:
|
|
@@ -204,7 +203,7 @@ def submit_job(source_file, target_file, source_lang, target_lang):
|
|
| 204 |
)
|
| 205 |
|
| 206 |
status = f"π Job **{job_id[:8]}** submitted. Processing `{src_name}` β `{tgt_name}`."
|
| 207 |
-
return job_id, status
|
| 208 |
|
| 209 |
|
| 210 |
def load_job(job_id):
|
|
@@ -219,7 +218,6 @@ def load_job(job_id):
|
|
| 219 |
gr.update(value=None, interactive=True),
|
| 220 |
gr.update(interactive=True),
|
| 221 |
gr.update(visible=False),
|
| 222 |
-
gr.update(visible=False),
|
| 223 |
)
|
| 224 |
|
| 225 |
job = manager.get_job(job_id)
|
|
@@ -230,25 +228,14 @@ def load_job(job_id):
|
|
| 230 |
status = f"Processing `{job['source_name']}` and `{job['target_name']}`β¦"
|
| 231 |
progress = job.get("progress")
|
| 232 |
if progress and progress["total"] > 0:
|
| 233 |
-
|
| 234 |
step = progress["step"]
|
| 235 |
total = progress["total"]
|
| 236 |
-
|
| 237 |
percent = (step / total) * 100
|
| 238 |
-
|
| 239 |
-
detail = f"{title} {step}/{total} ({percent:.0f}%)"
|
| 240 |
-
status += f"\n\n**{detail}**"
|
| 241 |
-
bar_html = f"""
|
| 242 |
-
<div style="width:100%; background-color:#eee; border-radius:4px;">
|
| 243 |
-
<div style="width:{percent}%; background-color:#4CAF50; height:20px; border-radius:4px; text-align:center; color:white; font-size:12px; line-height:20px;">
|
| 244 |
-
{percent:.0f}%
|
| 245 |
-
</div>
|
| 246 |
-
</div>
|
| 247 |
-
"""
|
| 248 |
-
progress_bar_update = gr.update(value=bar_html, visible=True)
|
| 249 |
else:
|
| 250 |
status += f" (initializing)"
|
| 251 |
-
progress_bar_update = gr.update(visible=False)
|
| 252 |
|
| 253 |
output = gr.update(value=None, visible=False)
|
| 254 |
clear_file = gr.update(value=None, interactive=False)
|
|
@@ -263,7 +250,6 @@ def load_job(job_id):
|
|
| 263 |
clear_file,
|
| 264 |
gr.update(interactive=False),
|
| 265 |
cancel_visible,
|
| 266 |
-
progress_bar_update,
|
| 267 |
)
|
| 268 |
|
| 269 |
elif job["status"] == "done":
|
|
@@ -280,7 +266,6 @@ def load_job(job_id):
|
|
| 280 |
clear_file,
|
| 281 |
gr.update(interactive=True),
|
| 282 |
gr.update(visible=False),
|
| 283 |
-
gr.update(visible=False),
|
| 284 |
)
|
| 285 |
else:
|
| 286 |
status = f"β Error: {job['status']}"
|
|
@@ -295,14 +280,13 @@ def load_job(job_id):
|
|
| 295 |
clear_file,
|
| 296 |
gr.update(interactive=True),
|
| 297 |
gr.update(visible=False),
|
| 298 |
-
gr.update(visible=False),
|
| 299 |
)
|
| 300 |
|
| 301 |
|
| 302 |
def cancel_current_job(job_id):
|
| 303 |
if job_id:
|
| 304 |
manager.cancel(job_id)
|
| 305 |
-
return "", gr.update(visible=False)
|
| 306 |
|
| 307 |
|
| 308 |
with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
@@ -336,13 +320,12 @@ with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
| 336 |
cancel_btn = gr.Button("β Cancel", variant="stop", visible=False)
|
| 337 |
refresh_btn = gr.Button("π Check Status")
|
| 338 |
status_msg = gr.Markdown("")
|
| 339 |
-
progress_bar = gr.HTML(visible=False)
|
| 340 |
output_file = gr.File(label="Download Bilingual EPUB", interactive=False, visible=False)
|
| 341 |
|
| 342 |
process_btn.click(
|
| 343 |
fn=submit_job,
|
| 344 |
inputs=[source_file, target_file, source_lang, target_lang],
|
| 345 |
-
outputs=[job_state, status_msg
|
| 346 |
).then(
|
| 347 |
fn=load_job,
|
| 348 |
inputs=job_state,
|
|
@@ -356,14 +339,13 @@ with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
| 356 |
target_file,
|
| 357 |
process_btn,
|
| 358 |
cancel_btn,
|
| 359 |
-
progress_bar,
|
| 360 |
],
|
| 361 |
)
|
| 362 |
|
| 363 |
cancel_btn.click(
|
| 364 |
fn=cancel_current_job,
|
| 365 |
inputs=job_state,
|
| 366 |
-
outputs=[job_state, cancel_btn
|
| 367 |
).then(
|
| 368 |
fn=load_job,
|
| 369 |
inputs=job_state,
|
|
@@ -377,7 +359,6 @@ with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
| 377 |
target_file,
|
| 378 |
process_btn,
|
| 379 |
cancel_btn,
|
| 380 |
-
progress_bar,
|
| 381 |
],
|
| 382 |
)
|
| 383 |
|
|
@@ -394,7 +375,6 @@ with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
| 394 |
target_file,
|
| 395 |
process_btn,
|
| 396 |
cancel_btn,
|
| 397 |
-
progress_bar,
|
| 398 |
],
|
| 399 |
)
|
| 400 |
|
|
@@ -411,7 +391,6 @@ with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
| 411 |
target_file,
|
| 412 |
process_btn,
|
| 413 |
cancel_btn,
|
| 414 |
-
progress_bar,
|
| 415 |
],
|
| 416 |
)
|
| 417 |
|
|
|
|
| 23 |
|
| 24 |
status_file.write_text("processing")
|
| 25 |
|
| 26 |
+
def progress_callback(phase_id, description: str, step: int, total: int, message: str = None):
|
| 27 |
data = {
|
| 28 |
+
"description": description,
|
| 29 |
"step": step,
|
| 30 |
"total": total,
|
|
|
|
| 31 |
"timestamp": time.time()
|
| 32 |
}
|
| 33 |
with open(progress_file, "w") as f:
|
|
|
|
| 203 |
)
|
| 204 |
|
| 205 |
status = f"π Job **{job_id[:8]}** submitted. Processing `{src_name}` β `{tgt_name}`."
|
| 206 |
+
return job_id, status
|
| 207 |
|
| 208 |
|
| 209 |
def load_job(job_id):
|
|
|
|
| 218 |
gr.update(value=None, interactive=True),
|
| 219 |
gr.update(interactive=True),
|
| 220 |
gr.update(visible=False),
|
|
|
|
| 221 |
)
|
| 222 |
|
| 223 |
job = manager.get_job(job_id)
|
|
|
|
| 228 |
status = f"Processing `{job['source_name']}` and `{job['target_name']}`β¦"
|
| 229 |
progress = job.get("progress")
|
| 230 |
if progress and progress["total"] > 0:
|
| 231 |
+
phase_id = progress.get("phase_id", "processing")
|
| 232 |
step = progress["step"]
|
| 233 |
total = progress["total"]
|
| 234 |
+
description = progress["description"]
|
| 235 |
percent = (step / total) * 100
|
| 236 |
+
status += f"\n\n{description} {step}/{total} ({percent:.0f}%)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
else:
|
| 238 |
status += f" (initializing)"
|
|
|
|
| 239 |
|
| 240 |
output = gr.update(value=None, visible=False)
|
| 241 |
clear_file = gr.update(value=None, interactive=False)
|
|
|
|
| 250 |
clear_file,
|
| 251 |
gr.update(interactive=False),
|
| 252 |
cancel_visible,
|
|
|
|
| 253 |
)
|
| 254 |
|
| 255 |
elif job["status"] == "done":
|
|
|
|
| 266 |
clear_file,
|
| 267 |
gr.update(interactive=True),
|
| 268 |
gr.update(visible=False),
|
|
|
|
| 269 |
)
|
| 270 |
else:
|
| 271 |
status = f"β Error: {job['status']}"
|
|
|
|
| 280 |
clear_file,
|
| 281 |
gr.update(interactive=True),
|
| 282 |
gr.update(visible=False),
|
|
|
|
| 283 |
)
|
| 284 |
|
| 285 |
|
| 286 |
def cancel_current_job(job_id):
|
| 287 |
if job_id:
|
| 288 |
manager.cancel(job_id)
|
| 289 |
+
return "", gr.update(visible=False)
|
| 290 |
|
| 291 |
|
| 292 |
with gr.Blocks(title="π Bilingual Book Builder") as demo:
|
|
|
|
| 320 |
cancel_btn = gr.Button("β Cancel", variant="stop", visible=False)
|
| 321 |
refresh_btn = gr.Button("π Check Status")
|
| 322 |
status_msg = gr.Markdown("")
|
|
|
|
| 323 |
output_file = gr.File(label="Download Bilingual EPUB", interactive=False, visible=False)
|
| 324 |
|
| 325 |
process_btn.click(
|
| 326 |
fn=submit_job,
|
| 327 |
inputs=[source_file, target_file, source_lang, target_lang],
|
| 328 |
+
outputs=[job_state, status_msg],
|
| 329 |
).then(
|
| 330 |
fn=load_job,
|
| 331 |
inputs=job_state,
|
|
|
|
| 339 |
target_file,
|
| 340 |
process_btn,
|
| 341 |
cancel_btn,
|
|
|
|
| 342 |
],
|
| 343 |
)
|
| 344 |
|
| 345 |
cancel_btn.click(
|
| 346 |
fn=cancel_current_job,
|
| 347 |
inputs=job_state,
|
| 348 |
+
outputs=[job_state, cancel_btn],
|
| 349 |
).then(
|
| 350 |
fn=load_job,
|
| 351 |
inputs=job_state,
|
|
|
|
| 359 |
target_file,
|
| 360 |
process_btn,
|
| 361 |
cancel_btn,
|
|
|
|
| 362 |
],
|
| 363 |
)
|
| 364 |
|
|
|
|
| 375 |
target_file,
|
| 376 |
process_btn,
|
| 377 |
cancel_btn,
|
|
|
|
| 378 |
],
|
| 379 |
)
|
| 380 |
|
|
|
|
| 391 |
target_file,
|
| 392 |
process_btn,
|
| 393 |
cancel_btn,
|
|
|
|
| 394 |
],
|
| 395 |
)
|
| 396 |
|