Spaces:
Running
on
Zero
Running
on
Zero
gokaygokay
commited on
Commit
·
ef64599
1
Parent(s):
0038320
first lora
Browse files- README.md +0 -13
- flux_lora.py → app.py +108 -108
- requirements.txt +22 -18
README.md
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: FLUX.1-dev + Captioner
|
3 |
-
emoji: 🐨
|
4 |
-
colorFrom: blue
|
5 |
-
colorTo: indigo
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.37.2
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flux_lora.py → app.py
RENAMED
@@ -1,109 +1,109 @@
|
|
1 |
-
import spaces
|
2 |
-
import argparse
|
3 |
-
import os
|
4 |
-
import time
|
5 |
-
from os import path
|
6 |
-
from safetensors.torch import load_file
|
7 |
-
from huggingface_hub import hf_hub_download
|
8 |
-
|
9 |
-
cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
|
10 |
-
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
11 |
-
os.environ["HF_HUB_CACHE"] = cache_path
|
12 |
-
os.environ["HF_HOME"] = cache_path
|
13 |
-
|
14 |
-
import gradio as gr
|
15 |
-
import torch
|
16 |
-
from diffusers import FluxPipeline
|
17 |
-
|
18 |
-
torch.backends.cuda.matmul.allow_tf32 = True
|
19 |
-
|
20 |
-
class timer:
|
21 |
-
def __init__(self, method_name="timed process"):
|
22 |
-
self.method = method_name
|
23 |
-
def __enter__(self):
|
24 |
-
self.start = time.time()
|
25 |
-
print(f"{self.method} starts")
|
26 |
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
27 |
-
end = time.time()
|
28 |
-
print(f"{self.method} took {str(round(end - self.start, 2))}s")
|
29 |
-
|
30 |
-
if not path.exists(cache_path):
|
31 |
-
os.makedirs(cache_path, exist_ok=True)
|
32 |
-
|
33 |
-
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
34 |
-
pipe.load_lora_weights(hf_hub_download("
|
35 |
-
pipe.fuse_lora(lora_scale=
|
36 |
-
pipe.to(device="cuda", dtype=torch.bfloat16)
|
37 |
-
|
38 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
39 |
-
gr.Markdown(
|
40 |
-
"""
|
41 |
-
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
42 |
-
<h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; display: contents;">Hyper-FLUX-8steps-LoRA</h1>
|
43 |
-
<p style="font-size: 1rem; margin-bottom: 1.5rem;">AutoML team from ByteDance</p>
|
44 |
-
</div>
|
45 |
-
"""
|
46 |
-
)
|
47 |
-
|
48 |
-
with gr.Row():
|
49 |
-
with gr.Column(scale=3):
|
50 |
-
with gr.Group():
|
51 |
-
prompt = gr.Textbox(
|
52 |
-
label="Your Image Description",
|
53 |
-
placeholder="E.g., A serene landscape with mountains and a lake at sunset",
|
54 |
-
lines=3
|
55 |
-
)
|
56 |
-
|
57 |
-
with gr.Accordion("Advanced Settings", open=False):
|
58 |
-
with gr.Group():
|
59 |
-
with gr.Row():
|
60 |
-
height = gr.Slider(label="Height", minimum=256, maximum=1152, step=64, value=1024)
|
61 |
-
width = gr.Slider(label="Width", minimum=256, maximum=1152, step=64, value=1024)
|
62 |
-
|
63 |
-
with gr.Row():
|
64 |
-
steps = gr.Slider(label="Inference Steps", minimum=
|
65 |
-
scales = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=5.0, step=0.1, value=3.5)
|
66 |
-
|
67 |
-
seed = gr.Number(label="Seed (for reproducibility)", value=3413, precision=0)
|
68 |
-
|
69 |
-
generate_btn = gr.Button("Generate Image", variant="primary", scale=1)
|
70 |
-
|
71 |
-
with gr.Column(scale=4):
|
72 |
-
output = gr.Image(label="Your Generated Image")
|
73 |
-
|
74 |
-
gr.Markdown(
|
75 |
-
"""
|
76 |
-
<div style="max-width: 650px; margin: 2rem auto; padding: 1rem; border-radius: 10px; background-color: #f0f0f0;">
|
77 |
-
<h2 style="font-size: 1.5rem; margin-bottom: 1rem;">How to Use</h2>
|
78 |
-
<ol style="padding-left: 1.5rem;">
|
79 |
-
<li>Enter a detailed description of the image you want to create.</li>
|
80 |
-
<li>Adjust advanced settings if desired (tap to expand).</li>
|
81 |
-
<li>Tap "Generate Image" and wait for your creation!</li>
|
82 |
-
</ol>
|
83 |
-
<p style="margin-top: 1rem; font-style: italic;">Tip: Be specific in your description for best results!</p>
|
84 |
-
</div>
|
85 |
-
"""
|
86 |
-
)
|
87 |
-
|
88 |
-
@spaces.GPU
|
89 |
-
def process_image(height, width, steps, scales, prompt, seed):
|
90 |
-
global pipe
|
91 |
-
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
|
92 |
-
return pipe(
|
93 |
-
prompt=[prompt],
|
94 |
-
generator=torch.Generator().manual_seed(int(seed)),
|
95 |
-
num_inference_steps=int(steps),
|
96 |
-
guidance_scale=float(scales),
|
97 |
-
height=int(height),
|
98 |
-
width=int(width),
|
99 |
-
max_sequence_length=256
|
100 |
-
).images[0]
|
101 |
-
|
102 |
-
generate_btn.click(
|
103 |
-
process_image,
|
104 |
-
inputs=[height, width, steps, scales, prompt, seed],
|
105 |
-
outputs=output
|
106 |
-
)
|
107 |
-
|
108 |
-
if __name__ == "__main__":
|
109 |
demo.launch()
|
|
|
1 |
+
import spaces
|
2 |
+
import argparse
|
3 |
+
import os
|
4 |
+
import time
|
5 |
+
from os import path
|
6 |
+
from safetensors.torch import load_file
|
7 |
+
from huggingface_hub import hf_hub_download
|
8 |
+
|
9 |
+
cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
|
10 |
+
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
11 |
+
os.environ["HF_HUB_CACHE"] = cache_path
|
12 |
+
os.environ["HF_HOME"] = cache_path
|
13 |
+
|
14 |
+
import gradio as gr
|
15 |
+
import torch
|
16 |
+
from diffusers import FluxPipeline
|
17 |
+
|
18 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
19 |
+
|
20 |
+
class timer:
|
21 |
+
def __init__(self, method_name="timed process"):
|
22 |
+
self.method = method_name
|
23 |
+
def __enter__(self):
|
24 |
+
self.start = time.time()
|
25 |
+
print(f"{self.method} starts")
|
26 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
27 |
+
end = time.time()
|
28 |
+
print(f"{self.method} took {str(round(end - self.start, 2))}s")
|
29 |
+
|
30 |
+
if not path.exists(cache_path):
|
31 |
+
os.makedirs(cache_path, exist_ok=True)
|
32 |
+
|
33 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
34 |
+
pipe.load_lora_weights(hf_hub_download("gokaygokay/Flux-Game-Assets-LoRA-v2", "game_asst.safetensors"))
|
35 |
+
pipe.fuse_lora(lora_scale=1)
|
36 |
+
pipe.to(device="cuda", dtype=torch.bfloat16)
|
37 |
+
|
38 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
39 |
+
gr.Markdown(
|
40 |
+
"""
|
41 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
42 |
+
<h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; display: contents;">Hyper-FLUX-8steps-LoRA</h1>
|
43 |
+
<p style="font-size: 1rem; margin-bottom: 1.5rem;">AutoML team from ByteDance</p>
|
44 |
+
</div>
|
45 |
+
"""
|
46 |
+
)
|
47 |
+
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column(scale=3):
|
50 |
+
with gr.Group():
|
51 |
+
prompt = gr.Textbox(
|
52 |
+
label="Your Image Description",
|
53 |
+
placeholder="E.g., A serene landscape with mountains and a lake at sunset",
|
54 |
+
lines=3
|
55 |
+
)
|
56 |
+
|
57 |
+
with gr.Accordion("Advanced Settings", open=False):
|
58 |
+
with gr.Group():
|
59 |
+
with gr.Row():
|
60 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1152, step=64, value=1024)
|
61 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1152, step=64, value=1024)
|
62 |
+
|
63 |
+
with gr.Row():
|
64 |
+
steps = gr.Slider(label="Inference Steps", minimum=10, maximum=50, step=1, value=28)
|
65 |
+
scales = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=5.0, step=0.1, value=3.5)
|
66 |
+
|
67 |
+
seed = gr.Number(label="Seed (for reproducibility)", value=3413, precision=0)
|
68 |
+
|
69 |
+
generate_btn = gr.Button("Generate Image", variant="primary", scale=1)
|
70 |
+
|
71 |
+
with gr.Column(scale=4):
|
72 |
+
output = gr.Image(label="Your Generated Image")
|
73 |
+
|
74 |
+
gr.Markdown(
|
75 |
+
"""
|
76 |
+
<div style="max-width: 650px; margin: 2rem auto; padding: 1rem; border-radius: 10px; background-color: #f0f0f0;">
|
77 |
+
<h2 style="font-size: 1.5rem; margin-bottom: 1rem;">How to Use</h2>
|
78 |
+
<ol style="padding-left: 1.5rem;">
|
79 |
+
<li>Enter a detailed description of the image you want to create.</li>
|
80 |
+
<li>Adjust advanced settings if desired (tap to expand).</li>
|
81 |
+
<li>Tap "Generate Image" and wait for your creation!</li>
|
82 |
+
</ol>
|
83 |
+
<p style="margin-top: 1rem; font-style: italic;">Tip: Be specific in your description for best results!</p>
|
84 |
+
</div>
|
85 |
+
"""
|
86 |
+
)
|
87 |
+
|
88 |
+
@spaces.GPU
|
89 |
+
def process_image(height, width, steps, scales, prompt, seed):
|
90 |
+
global pipe
|
91 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
|
92 |
+
return pipe(
|
93 |
+
prompt=[prompt],
|
94 |
+
generator=torch.Generator().manual_seed(int(seed)),
|
95 |
+
num_inference_steps=int(steps),
|
96 |
+
guidance_scale=float(scales),
|
97 |
+
height=int(height),
|
98 |
+
width=int(width),
|
99 |
+
max_sequence_length=256
|
100 |
+
).images[0]
|
101 |
+
|
102 |
+
generate_btn.click(
|
103 |
+
process_image,
|
104 |
+
inputs=[height, width, steps, scales, prompt, seed],
|
105 |
+
outputs=output
|
106 |
+
)
|
107 |
+
|
108 |
+
if __name__ == "__main__":
|
109 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,19 +1,23 @@
|
|
1 |
-
torch
|
2 |
-
torchvision
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
numpy>=1.26.4
|
11 |
-
huggingface-hub>=0.23.4
|
12 |
-
rembg[gpu]>=2.0.57
|
13 |
-
gradio-litmodel3d>=0.0.1
|
14 |
accelerate
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch==2.1.0
|
2 |
+
torchvision==0.16.0
|
3 |
+
torchaudio==2.1.0
|
4 |
+
pytorch-lightning==2.1.2
|
5 |
+
einops
|
6 |
+
omegaconf
|
7 |
+
deepspeed
|
8 |
+
torchmetrics
|
9 |
+
webdataset
|
|
|
|
|
|
|
|
|
10 |
accelerate
|
11 |
+
tensorboard
|
12 |
+
PyMCubes
|
13 |
+
trimesh
|
14 |
+
rembg
|
15 |
+
transformers==4.34.1
|
16 |
+
diffusers==0.19.3
|
17 |
+
bitsandbytes
|
18 |
+
imageio[ffmpeg]
|
19 |
+
xatlas
|
20 |
+
plyfile
|
21 |
+
xformers==0.0.22.post7
|
22 |
+
git+https://github.com/NVlabs/nvdiffrast/
|
23 |
+
huggingface-hub
|