Alexander Bagus commited on
Commit
c8a5fa7
·
1 Parent(s): b34ad97

update static files

Browse files
Files changed (3) hide show
  1. app.py +5 -2
  2. static/static/footer.md +43 -0
  3. static/static/header.html +11 -0
app.py CHANGED
@@ -7,11 +7,10 @@ from diffsynth.pipelines.z_image import (
7
  )
8
  from diffsynth.pipelines.z_image import ZImagePipeline as ZImagePipelineDs
9
  from diffusers import ZImagePipeline
10
- from safetensors.torch import save_file, load_file
11
  import torch
12
  from PIL import Image
13
  from pathlib import Path
14
- from utils import repo_utils, image_utils, prompt_utils
15
  from huggingface_hub import snapshot_download
16
  import glob
17
 
@@ -173,16 +172,20 @@ def generate_lora(
173
  return False
174
 
175
  progress(0.1, desc="Processing images...")
 
176
  pil_images = [Image.open(filepath).convert("RGB") for filepath, _ in input_images]
177
 
178
  progress(0.3, desc="Encoding images to LoRA...")
 
179
  # Model inference
180
  with torch.no_grad():
181
  embs = ZImageUnit_Image2LoRAEncode().process(pipe_lora, image2lora_images=pil_images)
182
  progress(0.7, desc="Decoding LoRA weights...")
 
183
  lora = ZImageUnit_Image2LoRADecode().process(pipe_lora, **embs)["lora"]
184
 
185
  progress(0.9, desc="Saving LoRA file...")
 
186
  lora_name = f"{ulid}.safetensors"
187
  lora_path = f"loras/{lora_name}"
188
 
 
7
  )
8
  from diffsynth.pipelines.z_image import ZImagePipeline as ZImagePipelineDs
9
  from diffusers import ZImagePipeline
10
+ from safetensors.torch import save_file
11
  import torch
12
  from PIL import Image
13
  from pathlib import Path
 
14
  from huggingface_hub import snapshot_download
15
  import glob
16
 
 
172
  return False
173
 
174
  progress(0.1, desc="Processing images...")
175
+ print("progress: step 1")
176
  pil_images = [Image.open(filepath).convert("RGB") for filepath, _ in input_images]
177
 
178
  progress(0.3, desc="Encoding images to LoRA...")
179
+ print("progress: step 2")
180
  # Model inference
181
  with torch.no_grad():
182
  embs = ZImageUnit_Image2LoRAEncode().process(pipe_lora, image2lora_images=pil_images)
183
  progress(0.7, desc="Decoding LoRA weights...")
184
+ print("progress: step 3")
185
  lora = ZImageUnit_Image2LoRADecode().process(pipe_lora, **embs)["lora"]
186
 
187
  progress(0.9, desc="Saving LoRA file...")
188
+ print("progress: step 4")
189
  lora_name = f"{ulid}.safetensors"
190
  lora_path = f"loras/{lora_name}"
191
 
static/static/footer.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ ## Step by ste instruction
4
+ - **Use jpg format**, upload a minimum 1 image to "Input Images".
5
+ - Press "Generate LoRA".
6
+ - After a moment, your LoRA will be ready to download.
7
+ - Press "Generate image" to use LoRA above.
8
+ The generated image will have similar style as the sample images you uploaded.
9
+
10
+ If you're using Python, you can use the LoRA above to generate an image using instructions from DiffSynth-Studio (link below).
11
+
12
+ **And if you're happy with the result, please support me by pressing the like button 😄**
13
+
14
+ ## For ComfyUI
15
+ - Download the generated LoRA.
16
+ - Use this sample workflow: <https://files.catbox.moe/4c6w5f.json>
17
+ - Replace the lightning LoRA with the LoRA you've been downloaded before.
18
+
19
+ Credit to *u/GBJI* from Reddit for the workflow.
20
+
21
+ ## Question and Answer
22
+ **What can this app do?**
23
+ This demo helps you make new pictures that look like your example pictures, using a LoRA.
24
+
25
+ **What is a lora?**
26
+ A LoRA (Low-Rank Adaptation) is a small add-on for a pre-trained image generation model. It's trained on a specific set of images to teach the model a new style, character, or object without retraining the entire model.
27
+
28
+ **Is it different from IP Adapter?**
29
+ Yes, it is different.
30
+ IP Adapters are for style transfer (making your image look like a reference image). LoRA is for fine-tuning (teaching the model new concepts or styles).
31
+
32
+ ## Features
33
+ - Use a single image to generate LoRA (though more images are better).
34
+ - You can download the LoRA you generate.
35
+ - There's also an option to generate an image using the LoRA you created.
36
+
37
+ ## Speed
38
+ - LoRA generation takes about 20 seconds (H200 ZeroGPU).
39
+ - Image generation using LoRA takes about 50 seconds (maybe something wrong here).
40
+
41
+ ## References
42
+ - **DiffSynth-Studio**: <https://huggingface.co/DiffSynth-Studio/Qwen-Image-i2L>
43
+
static/static/header.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 600px; margin: 0 auto;">
2
+ <h1>
3
+ Qwen Image to LoRA
4
+ </h1>
5
+ <div class="grid-container" >
6
+ <p>
7
+ Generate LoRA from a few images.
8
+ <br>
9
+ Demo by <a href="https://aisudo.com/" target="_blank">AiSudo</a> 😊
10
+ </div>
11
+ </div>