Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -283,13 +283,7 @@ async def upload_images(
|
|
283 |
|
284 |
|
285 |
|
286 |
-
|
287 |
-
try:
|
288 |
-
FOLDER_IN_REPO = folder_path
|
289 |
-
print(f"🚀 Auto-run triggered for: {FOLDER_IN_REPO}")
|
290 |
-
# Do your training etc...
|
291 |
-
except Exception as e:
|
292 |
-
print(f"❌ auto_run_lora_from_repo failed: {str(e)}")
|
293 |
|
294 |
|
295 |
|
@@ -507,132 +501,22 @@ def recursive_update(d, u):
|
|
507 |
|
508 |
|
509 |
|
510 |
-
@spaces.GPU(duration=50)
|
511 |
-
def start_training0(
|
512 |
-
lora_name,
|
513 |
-
concept_sentence,
|
514 |
-
steps,
|
515 |
-
lr,
|
516 |
-
rank,
|
517 |
-
model_to_train,
|
518 |
-
low_vram,
|
519 |
-
dataset_folder,
|
520 |
-
sample_1,
|
521 |
-
sample_2,
|
522 |
-
sample_3,
|
523 |
-
use_more_advanced_options,
|
524 |
-
more_advanced_options,
|
525 |
-
):
|
526 |
-
try:
|
527 |
-
user = whoami()
|
528 |
-
username = user.get("name", "anonymous")
|
529 |
-
push_to_hub = True
|
530 |
-
except:
|
531 |
-
username = "anonymous"
|
532 |
-
push_to_hub = False
|
533 |
-
|
534 |
-
slugged_lora_name = lora_name.replace(" ", "_").lower()
|
535 |
-
print(username)
|
536 |
-
|
537 |
-
# Load base config
|
538 |
-
config = {
|
539 |
-
"job": "extension",
|
540 |
-
"config": {
|
541 |
-
"name": slugged_lora_name,
|
542 |
-
"process": [
|
543 |
-
{ "type":"sd_trainer",
|
544 |
-
"model": {
|
545 |
-
"low_vram": low_vram,
|
546 |
-
"is_flux": True,
|
547 |
-
"quantize": True,
|
548 |
-
"name_or_path": "black-forest-labs/FLUX.1-dev"
|
549 |
-
},
|
550 |
-
"network": {
|
551 |
-
"linear": rank,
|
552 |
-
"linear_alpha": rank,
|
553 |
-
"type": "lora"
|
554 |
-
},
|
555 |
-
"train": {
|
556 |
-
"steps": steps,
|
557 |
-
"lr": lr,
|
558 |
-
"skip_first_sample": True,
|
559 |
-
"batch_size": 1,
|
560 |
-
"dtype": "bf16",
|
561 |
-
"gradient_accumulation_steps": 1,
|
562 |
-
"gradient_checkpointing": True,
|
563 |
-
"noise_scheduler": "flowmatch",
|
564 |
-
"optimizer": "adamw8bit",
|
565 |
-
"ema_config": {
|
566 |
-
"use_ema": True,
|
567 |
-
"ema_decay": 0.99
|
568 |
-
}
|
569 |
-
},
|
570 |
-
"datasets": [
|
571 |
-
{"folder_path": dataset_folder}
|
572 |
-
],
|
573 |
-
"save": {
|
574 |
-
"dtype": "float16",
|
575 |
-
"save_every": 10000,
|
576 |
-
"push_to_hub": push_to_hub,
|
577 |
-
"hf_repo_id": f"{username}/{slugged_lora_name}",
|
578 |
-
"hf_private": True,
|
579 |
-
"max_step_saves_to_keep": 4
|
580 |
-
},
|
581 |
-
"sample": {
|
582 |
-
"guidance_scale": 3.5,
|
583 |
-
"sample_every": steps,
|
584 |
-
"sample_steps": 28,
|
585 |
-
"width": 1024,
|
586 |
-
"height": 1024,
|
587 |
-
"walk_seed": True,
|
588 |
-
"seed": 42,
|
589 |
-
"sampler": "flowmatch",
|
590 |
-
"prompts": [p for p in [sample_1, sample_2, sample_3] if p]
|
591 |
-
},
|
592 |
-
"trigger_word": concept_sentence
|
593 |
-
}
|
594 |
-
]
|
595 |
-
}
|
596 |
-
}
|
597 |
-
|
598 |
-
# Apply advanced YAML overrides if any
|
599 |
-
# if use_more_advanced_options and more_advanced_options:
|
600 |
-
# advanced_config = yaml.safe_load(more_advanced_options)
|
601 |
-
# config["config"]["process"][0] = recursive_update(config["config"]["process"][0], advanced_config)
|
602 |
-
|
603 |
-
# Save YAML config
|
604 |
-
os.makedirs("/tmp/tmp_configs", exist_ok=True)
|
605 |
-
config_path = f"/tmp/tmp_configs/{uuid.uuid4()}_{slugged_lora_name}.yaml"
|
606 |
-
with open(config_path, "w") as f:
|
607 |
-
yaml.dump(config, f)
|
608 |
-
|
609 |
-
|
610 |
-
print(config_path)
|
611 |
-
# Simulate training
|
612 |
-
job = get_job(config_path)
|
613 |
-
job.run()
|
614 |
-
job.cleanup()
|
615 |
-
print(f"[INFO] Starting training with config: {config_path}")
|
616 |
-
print(json.dumps(config, indent=2))
|
617 |
-
return f"Training started successfully with config: {config_path}"
|
618 |
-
|
619 |
-
# ========== MAIN ENDPOINT ==========
|
620 |
-
|
621 |
-
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
|
|
628 |
|
629 |
|
630 |
@app.post("/train-from-hf")
|
631 |
-
def auto_run_lora_from_repo():
|
632 |
try:
|
|
|
633 |
# ✅ Static or dynamic config
|
634 |
REPO_ID = "rahul7star/ohamlab"
|
635 |
-
FOLDER_IN_REPO =
|
636 |
CONCEPT_SENTENCE = "ohamlab style"
|
637 |
LORA_NAME = "ohami_filter_autorun"
|
638 |
|
|
|
283 |
|
284 |
|
285 |
|
286 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
|
289 |
|
|
|
501 |
|
502 |
|
503 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
+
|
511 |
|
512 |
|
513 |
@app.post("/train-from-hf")
|
514 |
+
def auto_run_lora_from_repo(folder_path: str):
|
515 |
try:
|
516 |
+
print("Training has kickstarted")
|
517 |
# ✅ Static or dynamic config
|
518 |
REPO_ID = "rahul7star/ohamlab"
|
519 |
+
FOLDER_IN_REPO = folder_path
|
520 |
CONCEPT_SENTENCE = "ohamlab style"
|
521 |
LORA_NAME = "ohami_filter_autorun"
|
522 |
|