LHRuig commited on
Commit
7ae4cf1
·
verified ·
1 Parent(s): 1c1f2e1

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -57
app.py DELETED
@@ -1,57 +0,0 @@
1
- import os
2
- import subprocess
3
- import gradio as gr
4
- from caption import generate_caption # Your BLIP-2 captioning script
5
-
6
- # ===== 1. Install Kohya_SS Manually =====
7
- if not os.path.exists("kohya_ss"):
8
- print("⬇️ Cloning Kohya_SS...")
9
- os.system("git clone https://github.com/bmaltais/kohya_ss")
10
- os.chdir("kohya_ss")
11
- os.system("pip install -r requirements.txt")
12
- os.system("pip install .") # Editable install
13
- os.chdir("..")
14
-
15
- # ===== 2. Training Function =====
16
- def train_lora(images, trigger_word, model_choice="Flux"):
17
- # Save images
18
- os.makedirs("train", exist_ok=True)
19
- for i, img in enumerate(images):
20
- img_path = f"train/img_{i}.jpg"
21
- img.save(img_path)
22
- # Auto-caption (from caption.py)
23
- caption = generate_caption(img_path, trigger_word)
24
- with open(f"train/img_{i}.txt", "w") as f:
25
- f.write(caption)
26
-
27
- # Train LoRA (simplified Kohya_SS command)
28
- cmd = f"""
29
- python kohya_ss/train_network.py \
30
- --pretrained_model_name_or_path="{model_choice}" \
31
- --train_data_dir="train" \
32
- --output_dir="output" \
33
- --resolution=512 \
34
- --network_dim=64 \
35
- --lr=1e-4 \
36
- --max_train_steps=1000
37
- """
38
- subprocess.run(cmd, shell=True)
39
- return "output/lora.safetensors"
40
-
41
- # ===== 3. Gradio UI =====
42
- with gr.Blocks() as demo:
43
- gr.Markdown("## 🎨 1-Click LoRA Trainer")
44
- with gr.Row():
45
- images = gr.Files(label="Upload 30 Images", file_types=["image"])
46
- trigger = gr.Textbox(label="Trigger Word (e.g., 'my_char')")
47
- train_btn = gr.Button("🚀 Train LoRA")
48
- output = gr.File(label="Download LoRA")
49
-
50
- train_btn.click(
51
- train_lora,
52
- inputs=[images, trigger],
53
- outputs=output
54
- )
55
-
56
- if __name__ == "__main__":
57
- demo.launch()