Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -521,11 +521,13 @@ def start_training(
|
|
521 |
config_path = f"/tmp/tmp_configs/{uuid.uuid4()}_{slugged_lora_name}.yaml"
|
522 |
with open(config_path, "w") as f:
|
523 |
yaml.dump(config, f)
|
524 |
-
|
|
|
|
|
525 |
# Simulate training
|
526 |
-
job = get_job(config_path)
|
527 |
-
job.run()
|
528 |
-
job.cleanup()
|
529 |
print(f"[INFO] Starting training with config: {config_path}")
|
530 |
print(json.dumps(config, indent=2))
|
531 |
return f"Training started successfully with config: {config_path}"
|
@@ -632,77 +634,3 @@ def auto_run_lora_from_repo():
|
|
632 |
|
633 |
|
634 |
|
635 |
-
|
636 |
-
def _run_lora_from_repo():
|
637 |
-
try:
|
638 |
-
# Set HF cache path if not already set
|
639 |
-
os.environ["HF_HOME"] = "/tmp/hf_cache"
|
640 |
-
os.makedirs("/tmp/hf_cache", exist_ok=True)
|
641 |
-
|
642 |
-
# Create temporary directory to hold downloaded files
|
643 |
-
local_dir = Path(f"/tmp/{LORA_NAME}-{uuid.uuid4()}")
|
644 |
-
os.makedirs(local_dir, exist_ok=True)
|
645 |
-
|
646 |
-
# Download snapshot from model repo using allow_patterns
|
647 |
-
snapshot_path = snapshot_download(
|
648 |
-
repo_id=REPO_ID,
|
649 |
-
repo_type="model",
|
650 |
-
local_dir=local_dir,
|
651 |
-
local_dir_use_symlinks=False,
|
652 |
-
allow_patterns=[f"{FOLDER_IN_REPO}/*"], # only that folder
|
653 |
-
)
|
654 |
-
|
655 |
-
# Target subfolder inside the snapshot
|
656 |
-
image_dir = Path(snapshot_path) / FOLDER_IN_REPO
|
657 |
-
|
658 |
-
# Collect all image files (recursively)
|
659 |
-
image_paths = list(image_dir.rglob("*.jpg")) + \
|
660 |
-
list(image_dir.rglob("*.jpeg")) + \
|
661 |
-
list(image_dir.rglob("*.png"))
|
662 |
-
|
663 |
-
if not image_paths:
|
664 |
-
return JSONResponse(
|
665 |
-
status_code=400,
|
666 |
-
content={"error": "No images found in the HF repo folder."}
|
667 |
-
)
|
668 |
-
|
669 |
-
# Create auto captions
|
670 |
-
captions = [
|
671 |
-
f"Autogenerated caption for {img.stem} in the {CONCEPT_SENTENCE} [trigger]"
|
672 |
-
for img in image_paths
|
673 |
-
]
|
674 |
-
|
675 |
-
# Prepare dataset
|
676 |
-
dataset_path = create_dataset(image_paths, *captions)
|
677 |
-
|
678 |
-
# Start training
|
679 |
-
result = start_training(
|
680 |
-
lora_name=LORA_NAME,
|
681 |
-
concept_sentence=CONCEPT_SENTENCE,
|
682 |
-
steps=1000,
|
683 |
-
lr=4e-4,
|
684 |
-
rank=16,
|
685 |
-
model_to_train="dev",
|
686 |
-
low_vram=True,
|
687 |
-
dataset_folder=dataset_path,
|
688 |
-
sample_1=f"A stylized portrait using {CONCEPT_SENTENCE}",
|
689 |
-
sample_2=f"A cat in the {CONCEPT_SENTENCE}",
|
690 |
-
sample_3=f"A selfie processed in {CONCEPT_SENTENCE}",
|
691 |
-
use_more_advanced_options=True,
|
692 |
-
more_advanced_options="""
|
693 |
-
training:
|
694 |
-
seed: 42
|
695 |
-
precision: bf16
|
696 |
-
batch_size: 2
|
697 |
-
augmentation:
|
698 |
-
flip: true
|
699 |
-
color_jitter: true
|
700 |
-
"""
|
701 |
-
)
|
702 |
-
|
703 |
-
return {"message": result}
|
704 |
-
|
705 |
-
except PermissionError as pe:
|
706 |
-
return JSONResponse(status_code=500, content={"error": f"Permission denied: {pe}"})
|
707 |
-
except Exception as e:
|
708 |
-
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
521 |
config_path = f"/tmp/tmp_configs/{uuid.uuid4()}_{slugged_lora_name}.yaml"
|
522 |
with open(config_path, "w") as f:
|
523 |
yaml.dump(config, f)
|
524 |
+
|
525 |
+
|
526 |
+
print(config_path)
|
527 |
# Simulate training
|
528 |
+
# job = get_job(config_path)
|
529 |
+
# job.run()
|
530 |
+
# job.cleanup()
|
531 |
print(f"[INFO] Starting training with config: {config_path}")
|
532 |
print(json.dumps(config, indent=2))
|
533 |
return f"Training started successfully with config: {config_path}"
|
|
|
634 |
|
635 |
|
636 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|