Update app.py
Browse files
app.py
CHANGED
|
@@ -312,15 +312,18 @@ def start_training_wrapper(hf_token, model_name, new_repo_name, lora_r, lora_alp
|
|
| 312 |
thread.daemon = True
|
| 313 |
thread.start()
|
| 314 |
|
| 315 |
-
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
-
return new_job.id, gr.update(visible=True, value=f"
|
| 319 |
|
| 320 |
def get_job_update(job_id):
|
| 321 |
if job_id not in JOBS:
|
| 322 |
return (
|
| 323 |
-
"
|
| 324 |
"--:--",
|
| 325 |
"0%",
|
| 326 |
"",
|
|
@@ -329,84 +332,241 @@ def get_job_update(job_id):
|
|
| 329 |
|
| 330 |
job = JOBS[job_id]
|
| 331 |
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
-
|
| 335 |
|
| 336 |
result_comp = gr.update(visible=False)
|
| 337 |
if job.status == "COMPLETED" and job.repo_url:
|
| 338 |
-
result_comp = gr.update(visible=True, value=f"
|
| 339 |
|
| 340 |
-
return
|
| 341 |
|
| 342 |
def load_from_url(request: gr.Request):
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
|
|
|
|
|
|
|
|
|
| 347 |
return gr.update(selected="launch_tab"), ""
|
| 348 |
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
with gr.Row():
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
repo_name = gr.Textbox(label="New Repository Name", value="nucleus-model-v1")
|
| 362 |
-
datasets = gr.Textbox(label="Datasets (CSV format)", placeholder="Salesforce/fineweb_deduplicated", lines=4)
|
| 363 |
-
|
| 364 |
-
reasoning_toggle = gr.Checkbox(label="Enable Reasoning Core (GSM8K/Logic Injection)", value=False)
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
gr.Markdown("### LoRA Config")
|
| 373 |
-
lora_r = gr.Slider(8, 256, 32, step=8, label="Rank (r)")
|
| 374 |
-
lora_a = gr.Slider(8, 512, 64, step=8, label="Alpha")
|
| 375 |
-
lora_d = gr.Slider(0, 0.5, 0.05, label="Dropout")
|
| 376 |
|
| 377 |
-
with gr.
|
| 378 |
with gr.Row():
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
gen_json = gr.Code(label="generation_config.json", language="json")
|
| 382 |
-
|
| 383 |
-
launch_btn = gr.Button("Start Background Job", variant="primary")
|
| 384 |
-
|
| 385 |
-
job_info_area = gr.Group(visible=False)
|
| 386 |
-
with job_info_area:
|
| 387 |
-
new_job_id_display = gr.HTML()
|
| 388 |
-
share_link_display = gr.Textbox(label="Direct Monitor Link", interactive=False, show_copy_button=True)
|
| 389 |
-
|
| 390 |
-
with gr.TabItem("Job Monitor", id="monitor_tab"):
|
| 391 |
-
with gr.Row():
|
| 392 |
-
input_job_id = gr.Textbox(label="Enter Job ID", placeholder="xxxxxxxx")
|
| 393 |
-
refresh_btn = gr.Button("Refresh Status")
|
| 394 |
-
|
| 395 |
-
with gr.Row():
|
| 396 |
-
with gr.Column(scale=1):
|
| 397 |
-
status_display = gr.Textbox(label="Current Status", interactive=False)
|
| 398 |
-
created_display = gr.Textbox(label="Start Time", interactive=False)
|
| 399 |
-
final_link = gr.Markdown(visible=False)
|
| 400 |
|
| 401 |
-
with gr.
|
| 402 |
-
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
timer = gr.Timer(3000, active=False)
|
| 406 |
|
| 407 |
def activate_timer():
|
| 408 |
return gr.Timer(active=True)
|
| 409 |
-
|
| 410 |
demo.load(
|
| 411 |
load_from_url,
|
| 412 |
None,
|
|
@@ -418,7 +578,7 @@ with gr.Blocks(title="Nucleus Enterprise Native") as demo:
|
|
| 418 |
inputs=[hf_token, model_name, repo_name, lora_r, lora_a, lora_d, train_steps, lr, batch, datasets, reasoning_toggle, conf_json, tok_json, gen_json],
|
| 419 |
outputs=[new_job_id_display, job_info_area, share_link_display]
|
| 420 |
).then(
|
| 421 |
-
fn=lambda id: f"<
|
| 422 |
inputs=[new_job_id_display],
|
| 423 |
outputs=[new_job_id_display]
|
| 424 |
)
|
|
|
|
| 312 |
thread.daemon = True
|
| 313 |
thread.start()
|
| 314 |
|
| 315 |
+
try:
|
| 316 |
+
base_url = str(request.request.url).split('?')[0]
|
| 317 |
+
share_url = f"{base_url}?job_id={new_job.id}"
|
| 318 |
+
except:
|
| 319 |
+
share_url = f"Job ID: {new_job.id}"
|
| 320 |
|
| 321 |
+
return new_job.id, gr.update(visible=True, value=f"SESSION ID: {new_job.id}"), gr.update(visible=True, value=share_url)
|
| 322 |
|
| 323 |
def get_job_update(job_id):
|
| 324 |
if job_id not in JOBS:
|
| 325 |
return (
|
| 326 |
+
"<span style='color: #ef4444'>INVALID SESSION ID</span>",
|
| 327 |
"--:--",
|
| 328 |
"0%",
|
| 329 |
"",
|
|
|
|
| 332 |
|
| 333 |
job = JOBS[job_id]
|
| 334 |
|
| 335 |
+
log_html = "<br>".join([f"<div class='log-line'>{l}</div>" for l in job.logs[-50:]])
|
| 336 |
+
|
| 337 |
+
progress_html = f"""
|
| 338 |
+
<div class="p-bar-wrapper">
|
| 339 |
+
<div class="p-bar-fill" style="width: {job.progress * 100}%"></div>
|
| 340 |
+
</div>
|
| 341 |
+
<div class="p-text">{int(job.progress * 100)}% COMPLETE</div>
|
| 342 |
+
"""
|
| 343 |
+
|
| 344 |
+
status_map = {
|
| 345 |
+
"IDLE": "#94a3b8",
|
| 346 |
+
"ACTIVE": "#3b82f6",
|
| 347 |
+
"COMPLETED": "#10b981",
|
| 348 |
+
"FAILED": "#ef4444"
|
| 349 |
+
}
|
| 350 |
|
| 351 |
+
status_html = f"<span style='color: {status_map.get(job.status, '#fff')}; font-weight: 900; letter-spacing: 1px;'>{job.status}</span>"
|
| 352 |
|
| 353 |
result_comp = gr.update(visible=False)
|
| 354 |
if job.status == "COMPLETED" and job.repo_url:
|
| 355 |
+
result_comp = gr.update(visible=True, value=f"ACCESS MODEL ARTIFACT: {job.repo_url}")
|
| 356 |
|
| 357 |
+
return status_html, job.created_at, progress_html, log_html, result_comp
|
| 358 |
|
| 359 |
def load_from_url(request: gr.Request):
|
| 360 |
+
try:
|
| 361 |
+
params = request.query_params
|
| 362 |
+
job_id = params.get("job_id")
|
| 363 |
+
if job_id:
|
| 364 |
+
return gr.update(selected="monitor_tab"), job_id
|
| 365 |
+
except:
|
| 366 |
+
pass
|
| 367 |
return gr.update(selected="launch_tab"), ""
|
| 368 |
|
| 369 |
+
css = """
|
| 370 |
+
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;500;700&family=JetBrains+Mono:wght@400;700&display=swap');
|
| 371 |
+
|
| 372 |
+
:root {
|
| 373 |
+
--bg-dark: #0a0a0f;
|
| 374 |
+
--panel-dark: #13131f;
|
| 375 |
+
--primary: #6366f1;
|
| 376 |
+
--accent: #8b5cf6;
|
| 377 |
+
--text-main: #e2e8f0;
|
| 378 |
+
--text-dim: #64748b;
|
| 379 |
+
--border: #1e1e2e;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
body {
|
| 383 |
+
background-color: var(--bg-dark) !important;
|
| 384 |
+
font-family: 'Space Grotesk', sans-serif !important;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
.gradio-container {
|
| 388 |
+
background-color: transparent !important;
|
| 389 |
+
max-width: 1400px !important;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
.header-container {
|
| 393 |
+
text-align: center;
|
| 394 |
+
padding: 3rem 0;
|
| 395 |
+
background: radial-gradient(circle at center, rgba(99, 102, 241, 0.05) 0%, transparent 60%);
|
| 396 |
+
margin-bottom: 2rem;
|
| 397 |
+
border-bottom: 1px solid var(--border);
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
h1 {
|
| 401 |
+
font-size: 3.5rem;
|
| 402 |
+
background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
|
| 403 |
+
-webkit-background-clip: text;
|
| 404 |
+
-webkit-text-fill-color: transparent;
|
| 405 |
+
text-transform: uppercase;
|
| 406 |
+
letter-spacing: -2px;
|
| 407 |
+
margin-bottom: 0.5rem;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
.sub-header {
|
| 411 |
+
font-family: 'JetBrains Mono', monospace;
|
| 412 |
+
color: var(--primary);
|
| 413 |
+
font-size: 0.9rem;
|
| 414 |
+
letter-spacing: 2px;
|
| 415 |
+
text-transform: uppercase;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
.gr-box, .gr-panel {
|
| 419 |
+
background: var(--panel-dark) !important;
|
| 420 |
+
border: 1px solid var(--border) !important;
|
| 421 |
+
border-radius: 4px !important;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
.gr-input, .gr-textarea, .gr-number, .gr-dropdown {
|
| 425 |
+
background: #0d0d12 !important;
|
| 426 |
+
border: 1px solid var(--border) !important;
|
| 427 |
+
color: var(--text-main) !important;
|
| 428 |
+
font-family: 'JetBrains Mono', monospace;
|
| 429 |
+
font-size: 13px;
|
| 430 |
+
border-radius: 4px !important;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
.gr-input:focus {
|
| 434 |
+
border-color: var(--primary) !important;
|
| 435 |
+
box-shadow: 0 0 0 1px var(--primary) !important;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
.primary-btn {
|
| 439 |
+
background: var(--primary) !important;
|
| 440 |
+
border: none !important;
|
| 441 |
+
color: #fff !important;
|
| 442 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 443 |
+
text-transform: uppercase;
|
| 444 |
+
letter-spacing: 1px;
|
| 445 |
+
padding: 12px 24px !important;
|
| 446 |
+
border-radius: 2px !important;
|
| 447 |
+
transition: all 0.2s ease;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
.primary-btn:hover {
|
| 451 |
+
background: var(--accent) !important;
|
| 452 |
+
box-shadow: 0 0 15px rgba(99, 102, 241, 0.3);
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
.p-bar-wrapper {
|
| 456 |
+
width: 100%;
|
| 457 |
+
height: 4px;
|
| 458 |
+
background: #1e1e2e;
|
| 459 |
+
margin-top: 15px;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
.p-bar-fill {
|
| 463 |
+
height: 100%;
|
| 464 |
+
background: linear-gradient(90deg, var(--primary), var(--accent));
|
| 465 |
+
transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
.p-text {
|
| 469 |
+
font-family: 'JetBrains Mono', monospace;
|
| 470 |
+
font-size: 10px;
|
| 471 |
+
color: var(--primary);
|
| 472 |
+
text-align: right;
|
| 473 |
+
margin-top: 5px;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
.log-line {
|
| 477 |
+
font-family: 'JetBrains Mono', monospace;
|
| 478 |
+
font-size: 11px;
|
| 479 |
+
color: var(--text-dim);
|
| 480 |
+
padding: 2px 0;
|
| 481 |
+
border-bottom: 1px solid rgba(255,255,255,0.03);
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
.session-box {
|
| 485 |
+
background: rgba(99, 102, 241, 0.1);
|
| 486 |
+
border: 1px solid var(--primary);
|
| 487 |
+
color: var(--primary);
|
| 488 |
+
font-family: 'JetBrains Mono', monospace;
|
| 489 |
+
padding: 1rem;
|
| 490 |
+
text-align: center;
|
| 491 |
+
font-size: 1.2rem;
|
| 492 |
+
margin: 1rem 0;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
.label-wrap {
|
| 496 |
+
background: var(--panel-dark) !important;
|
| 497 |
+
border: 1px solid var(--border);
|
| 498 |
+
color: var(--text-main) !important;
|
| 499 |
+
}
|
| 500 |
+
"""
|
| 501 |
+
|
| 502 |
+
with gr.Blocks(title="Nucleus Enterprise") as demo:
|
| 503 |
+
gr.HTML(f"<style>{css}</style>")
|
| 504 |
+
with gr.Column():
|
| 505 |
+
gr.HTML("""
|
| 506 |
+
<div class="header-container">
|
| 507 |
+
<h1>Nucleus Enterprise</h1>
|
| 508 |
+
<div class="sub-header">Autonomous Neural Foundry // V.4.0</div>
|
| 509 |
+
</div>
|
| 510 |
+
""")
|
| 511 |
+
|
| 512 |
+
with gr.Tabs() as main_tabs:
|
| 513 |
+
with gr.TabItem("DEPLOYMENT", id="launch_tab"):
|
| 514 |
+
with gr.Row():
|
| 515 |
+
with gr.Column(scale=2):
|
| 516 |
+
with gr.Row():
|
| 517 |
+
hf_token = gr.Textbox(label="HUGGIGFACE KEY", type="password", value=os.getenv("HF_TOKEN", ""))
|
| 518 |
+
model_name = gr.Textbox(label="BASE MODEL ID", placeholder="Qwen/Qwen2.5-0.5B")
|
| 519 |
+
|
| 520 |
+
repo_name = gr.Textbox(label="TARGET REPOSITORY", value="nucleus-build-v1")
|
| 521 |
+
datasets = gr.Textbox(label="DATA STREAMS (CSV)", placeholder="Salesforce/fineweb_deduplicated", lines=4)
|
| 522 |
+
|
| 523 |
+
reasoning_toggle = gr.Checkbox(label="ENABLE REASONING CORE (INJECTS LOGIC DATASETS)", value=False, elem_id="reasoning-switch")
|
| 524 |
+
|
| 525 |
+
with gr.Column(scale=1):
|
| 526 |
+
gr.Markdown("### HYPERPARAMETERS")
|
| 527 |
+
train_steps = gr.Number(label="STEPS", value=100)
|
| 528 |
+
lr = gr.Number(label="LEARNING RATE", value=2e-4)
|
| 529 |
+
batch = gr.Number(label="BATCH SIZE", value=1)
|
| 530 |
+
|
| 531 |
+
gr.Markdown("### LORA ADAPTERS")
|
| 532 |
+
lora_r = gr.Slider(8, 256, 32, step=8, label="RANK")
|
| 533 |
+
lora_a = gr.Slider(8, 512, 64, step=8, label="ALPHA")
|
| 534 |
+
lora_d = gr.Slider(0, 0.5, 0.05, label="DROPOUT")
|
| 535 |
+
|
| 536 |
+
with gr.Accordion("ADVANCED CONFIGURATION INJECTION", open=False):
|
| 537 |
with gr.Row():
|
| 538 |
+
conf_json = gr.Code(label="CONFIG.JSON", language="json")
|
| 539 |
+
tok_json = gr.Code(label="TOKENIZER_CONFIG.JSON", language="json")
|
| 540 |
+
gen_json = gr.Code(label="GENERATION_CONFIG.JSON", language="json")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
|
| 542 |
+
launch_btn = gr.Button("INITIALIZE TRAINING SEQUENCE", elem_classes="primary-btn")
|
| 543 |
+
|
| 544 |
+
job_info_area = gr.Group(visible=False)
|
| 545 |
+
with job_info_area:
|
| 546 |
+
new_job_id_display = gr.HTML()
|
| 547 |
+
share_link_display = gr.Textbox(label="DIRECT MONITOR UPLINK", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
|
| 549 |
+
with gr.TabItem("TELEMETRY", id="monitor_tab"):
|
| 550 |
with gr.Row():
|
| 551 |
+
input_job_id = gr.Textbox(label="SESSION ID", placeholder="ENTER 8-DIGIT ID")
|
| 552 |
+
refresh_btn = gr.Button("ESTABLISH UPLINK", elem_classes="primary-btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
|
| 554 |
+
with gr.Row():
|
| 555 |
+
with gr.Column(scale=1):
|
| 556 |
+
status_display = gr.HTML(label="STATUS")
|
| 557 |
+
created_display = gr.Textbox(label="TIMESTAMP", interactive=False)
|
| 558 |
+
final_link = gr.Markdown(visible=False)
|
| 559 |
+
|
| 560 |
+
with gr.Column(scale=2):
|
| 561 |
+
progress_display = gr.HTML()
|
| 562 |
+
with gr.Accordion("SYSTEM LOGS", open=False):
|
| 563 |
+
logs_display = gr.HTML()
|
| 564 |
|
| 565 |
timer = gr.Timer(3000, active=False)
|
| 566 |
|
| 567 |
def activate_timer():
|
| 568 |
return gr.Timer(active=True)
|
| 569 |
+
|
| 570 |
demo.load(
|
| 571 |
load_from_url,
|
| 572 |
None,
|
|
|
|
| 578 |
inputs=[hf_token, model_name, repo_name, lora_r, lora_a, lora_d, train_steps, lr, batch, datasets, reasoning_toggle, conf_json, tok_json, gen_json],
|
| 579 |
outputs=[new_job_id_display, job_info_area, share_link_display]
|
| 580 |
).then(
|
| 581 |
+
fn=lambda id: f"<div class='session-box'>{id}</div>",
|
| 582 |
inputs=[new_job_id_display],
|
| 583 |
outputs=[new_job_id_display]
|
| 584 |
)
|