multimodalart HF Staff commited on
Commit
3cd11ff
·
verified ·
1 Parent(s): 3940a23

Initial Ideogram 4 NF4 demo

Browse files
Files changed (4) hide show
  1. README.md +8 -9
  2. __pycache__/app.cpython-312.pyc +0 -0
  3. app.py +87 -0
  4. requirements.txt +5 -0
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: Ideogram4
3
- emoji: 👀
4
- colorFrom: green
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 6.15.2
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
 
 
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Ideogram 4 (NF4) — diffusers preview
3
+ emoji: 🎨
4
+ colorFrom: indigo
5
+ colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 6.15.1
 
8
  app_file: app.py
9
+ short_description: Private preview of Ideogram 4 NF4 via diffusers PR
10
+ python_version: "3.12"
11
+ startup_duration_timeout: 1h
12
  ---
 
 
__pycache__/app.cpython-312.pyc ADDED
Binary file (4.63 kB). View file
 
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
3
+
4
+ import random
5
+
6
+ import spaces
7
+ import torch
8
+ import gradio as gr
9
+ from diffusers import Ideogram4Pipeline
10
+
11
+ MODEL_ID = "diffusers-internal-dev/ideogram-4-nf4"
12
+
13
+ pipe = Ideogram4Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
14
+ pipe.to("cuda")
15
+
16
+ MAX_SEED = 2**31 - 1
17
+
18
+
19
+ @spaces.GPU(duration=180)
20
+ def generate(
21
+ prompt: str,
22
+ width: int,
23
+ height: int,
24
+ num_inference_steps: int,
25
+ guidance_scale: float,
26
+ seed: int,
27
+ randomize_seed: bool,
28
+ progress=gr.Progress(track_tqdm=True),
29
+ ):
30
+ if randomize_seed or seed < 0:
31
+ seed = random.randint(0, MAX_SEED)
32
+ generator = torch.Generator(device="cuda").manual_seed(int(seed))
33
+
34
+ kwargs = dict(
35
+ prompt=prompt,
36
+ width=int(width),
37
+ height=int(height),
38
+ num_inference_steps=int(num_inference_steps),
39
+ generator=generator,
40
+ )
41
+ if guidance_scale > 0:
42
+ kwargs["guidance_scale"] = float(guidance_scale)
43
+ kwargs["guidance_schedule"] = None
44
+
45
+ image = pipe(**kwargs).images[0]
46
+ return image, seed
47
+
48
+
49
+ with gr.Blocks(title="Ideogram 4 (NF4) — diffusers preview") as demo:
50
+ gr.Markdown(
51
+ "## Ideogram 4 (NF4) — diffusers preview\n"
52
+ f"Private demo of [`{MODEL_ID}`](https://huggingface.co/{MODEL_ID}) using the "
53
+ "[diffusers PR #2](https://github.com/huggingface/diffusers-new-model-addition-ideogram/pull/2) "
54
+ "branch, running on ZeroGPU."
55
+ )
56
+
57
+ with gr.Row():
58
+ with gr.Column():
59
+ prompt = gr.Textbox(
60
+ label="Prompt",
61
+ value="A photo of a cat holding a sign that says hello world",
62
+ lines=3,
63
+ )
64
+ run = gr.Button("Generate", variant="primary")
65
+ with gr.Accordion("Advanced", open=False):
66
+ with gr.Row():
67
+ width = gr.Slider(512, 2048, value=1024, step=64, label="Width")
68
+ height = gr.Slider(512, 2048, value=1024, step=64, label="Height")
69
+ steps = gr.Slider(8, 64, value=48, step=1, label="Inference steps")
70
+ guidance = gr.Slider(
71
+ 0.0, 15.0, value=0.0, step=0.1,
72
+ label="Guidance scale (0 = recommended schedule: 7.0 → 3.0)",
73
+ )
74
+ with gr.Row():
75
+ seed = gr.Number(label="Seed", value=0, precision=0)
76
+ randomize = gr.Checkbox(label="Randomize seed", value=True)
77
+ with gr.Column():
78
+ out_image = gr.Image(label="Output", type="pil")
79
+ out_seed = gr.Number(label="Seed used", interactive=False, precision=0)
80
+
81
+ run.click(
82
+ generate,
83
+ inputs=[prompt, width, height, steps, guidance, seed, randomize],
84
+ outputs=[out_image, out_seed],
85
+ )
86
+
87
+ demo.queue().launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ git+https://github.com/huggingface/diffusers-new-model-addition-ideogram.git@jin.ideogram4
2
+ transformers
3
+ accelerate
4
+ bitsandbytes
5
+ sentencepiece