ILFM commited on
Commit
d8145bb
·
1 Parent(s): 398c168

1st Nunchaku upload

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +2 -2
  3. app.py +46 -0
  4. requirements.txt +10 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv/
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Flux Dev Nunchaku
3
- emoji: 📊
4
  colorFrom: indigo
5
  colorTo: indigo
6
  sdk: gradio
@@ -11,4 +11,4 @@ license: mit
11
  short_description: A nunchaku implementation with flux.1-dev
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Flux Dev Nunchaku
3
+ emoji: 🥷
4
  colorFrom: indigo
5
  colorTo: indigo
6
  sdk: gradio
 
11
  short_description: A nunchaku implementation with flux.1-dev
12
  ---
13
 
14
+ Check out the nunchaku framework at https://github.com/nunchaku-tech/nunchaku
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from diffusers import FluxPipeline
4
+
5
+ from nunchaku import NunchakuFluxTransformer2dModel
6
+ from nunchaku.utils import get_precision
7
+
8
+ dtype=torch.bfloat16
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+
11
+ precision = get_precision() # auto-detect your precision is 'int4' or 'fp4' based on your GPU
12
+ transformer = NunchakuFluxTransformer2dModel.from_pretrained(
13
+ f"nunchaku-tech/nunchaku-flux.1-dev/svdq-{precision}_r32-flux.1-dev.safetensors"
14
+ )
15
+ pipeline = FluxPipeline.from_pretrained(
16
+ "black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=dtype
17
+ ).to(device)
18
+
19
+ def generate_image(prompt: str, steps: int, guidance_scale: float):
20
+ if not prompt.strip():
21
+ raise gr.Error("Prompt cannot be empty.")
22
+
23
+ with torch.inference_mode(), torch.autocast(device, dtype=dtype):
24
+ result = pipeline(
25
+ prompt=prompt,
26
+ width=576,
27
+ height=1024,
28
+ num_inference_steps=steps,
29
+ guidance_scale=guidance_scale
30
+ )
31
+ return result.images[0]
32
+
33
+ # Minimal Gradio UI
34
+ demo = gr.Interface(
35
+ fn=generate_image,
36
+ inputs=[
37
+ gr.Textbox(label="Prompt", placeholder="Describe the scene..."),
38
+ gr.Slider(label="Inference Steps", minimum=5, maximum=50, step=1, value=20),
39
+ gr.Slider(label="Guidance Scale", minimum=0.1, maximum=10.0, step=0.1, value=3.5)
40
+ ],
41
+ outputs=gr.Image(label="Generated Image"),
42
+ title="FLUX Image Generator",
43
+ description="Prompt-based image generation using Flux + LoRA"
44
+ )
45
+
46
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # PyTorch, torchvision, torchaudio with CUDA 12.8 support
2
+ torch --index-url https://download.pytorch.org/whl/cu128
3
+ torchvision --index-url https://download.pytorch.org/whl/cu128
4
+ torchaudio --index-url https://download.pytorch.org/whl/cu128
5
+
6
+ # Nunchaku prebuilt wheel (exact version, torch 2.7, Python 3.11, Linux x86_64)
7
+ https://github.com/nunchaku-tech/nunchaku/releases/download/v0.3.1/nunchaku-0.3.1+torch2.7-cp310-cp310-linux_x86_64.whl
8
+
9
+ #Gradio instance
10
+ gradio