multimodalart HF Staff commited on
Commit
19d7eb5
·
verified ·
1 Parent(s): de324ea

Add cached gr.Examples (lazy) + generate defaults + fp8 link; remove stale tmp/ and __pycache__/

Browse files
__pycache__/app.cpython-312.pyc DELETED
Binary file (4.63 kB)
 
app.py CHANGED
@@ -127,7 +127,16 @@ def remote_upsample(prompt, width, height):
127
 
128
 
129
  @spaces.GPU(duration=240, size="xlarge")
130
- def generate(prompt, mode, upsampler, width, height, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
131
  t_enter = time.perf_counter()
132
  if randomize_seed or seed < 0:
133
  seed = random.randint(0, MAX_SEED)
@@ -199,6 +208,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="Ideogram 4") as demo:
199
  "Ideogram's first open-weights model — a 9.3B-parameter text-to-image foundation model at the "
200
  "forefront of design, with best-in-class text rendering.\n\n"
201
  "[Model](https://huggingface.co/ideogram-ai/ideogram-4-nf4) · "
 
202
  "[Blog](https://ideogram.ai/blog/ideogram-4.0/)"
203
  )
204
 
@@ -224,6 +234,19 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="Ideogram 4") as demo:
224
  out_image = gr.Image(label="Output", type="pil")
225
  out_caption = gr.JSON(label="Caption fed to the model (upsampled when enabled)")
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  run.click(
228
  generate,
229
  inputs=[prompt, mode, upsampler, width, height, seed, randomize],
 
127
 
128
 
129
  @spaces.GPU(duration=240, size="xlarge")
130
+ def generate(
131
+ prompt,
132
+ mode="Default · 20 steps",
133
+ upsampler=UPSAMPLERS[0],
134
+ width=1024,
135
+ height=1024,
136
+ seed=0,
137
+ randomize_seed=False,
138
+ progress=gr.Progress(track_tqdm=True),
139
+ ):
140
  t_enter = time.perf_counter()
141
  if randomize_seed or seed < 0:
142
  seed = random.randint(0, MAX_SEED)
 
208
  "Ideogram's first open-weights model — a 9.3B-parameter text-to-image foundation model at the "
209
  "forefront of design, with best-in-class text rendering.\n\n"
210
  "[Model](https://huggingface.co/ideogram-ai/ideogram-4-nf4) · "
211
+ "[Model (fp8)](https://huggingface.co/ideogram-ai/ideogram-4-fp8) · "
212
  "[Blog](https://ideogram.ai/blog/ideogram-4.0/)"
213
  )
214
 
 
234
  out_image = gr.Image(label="Output", type="pil")
235
  out_caption = gr.JSON(label="Caption fed to the model (upsampled when enabled)")
236
 
237
+ gr.Examples(
238
+ examples=[
239
+ ["a ginger cat wearing a tiny wizard hat reading a spellbook"],
240
+ ["an isometric illustration of a tiny city floating in the clouds"],
241
+ ["a golden retriever on a skateboard"],
242
+ ],
243
+ inputs=[prompt],
244
+ outputs=[out_image, seed, out_caption],
245
+ fn=generate,
246
+ cache_examples=True,
247
+ cache_mode="lazy",
248
+ )
249
+
250
  run.click(
251
  generate,
252
  inputs=[prompt, mode, upsampler, width, height, seed, randomize],
tmp/ideogram4_space/app.py DELETED
@@ -1,98 +0,0 @@
1
- import os
2
- import sys
3
-
4
- os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
5
-
6
- # Use the bundled diffusers source (PR #2: huggingface/diffusers-new-model-addition-ideogram).
7
- _HERE = os.path.dirname(os.path.abspath(__file__))
8
- sys.path.insert(0, os.path.join(_HERE, "diffusers_src", "src"))
9
-
10
- import random
11
-
12
- import spaces
13
- import torch
14
- import gradio as gr
15
- from diffusers import Ideogram4Pipeline
16
-
17
- MODEL_ID = "diffusers-internal-dev/ideogram-4-nf4"
18
-
19
- pipe = Ideogram4Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
20
- pipe.to("cuda")
21
-
22
- MAX_SEED = 2**31 - 1
23
-
24
-
25
- @spaces.GPU(duration=180)
26
- def generate(
27
- prompt: str,
28
- width: int,
29
- height: int,
30
- num_inference_steps: int,
31
- guidance_scale: float,
32
- seed: int,
33
- randomize_seed: bool,
34
- progress=gr.Progress(track_tqdm=True),
35
- ):
36
- if randomize_seed or seed < 0:
37
- seed = random.randint(0, MAX_SEED)
38
- generator = torch.Generator(device="cuda").manual_seed(int(seed))
39
-
40
- steps = int(num_inference_steps)
41
- kwargs = dict(
42
- prompt=prompt,
43
- width=int(width),
44
- height=int(height),
45
- num_inference_steps=steps,
46
- generator=generator,
47
- )
48
- if guidance_scale > 0:
49
- kwargs["guidance_scale"] = float(guidance_scale)
50
- kwargs["guidance_schedule"] = None
51
- else:
52
- # PR default is len 48 (7.0 x45 + 3.0 x3); rebuild it for any step count.
53
- tail = min(3, max(0, steps - 1))
54
- kwargs["guidance_schedule"] = (7.0,) * (steps - tail) + (3.0,) * tail
55
-
56
- image = pipe(**kwargs).images[0]
57
- return image, seed
58
-
59
-
60
- with gr.Blocks(title="Ideogram 4 (NF4) — diffusers preview") as demo:
61
- gr.Markdown(
62
- "## Ideogram 4 (NF4) — diffusers preview\n"
63
- f"Private demo of [`{MODEL_ID}`](https://huggingface.co/{MODEL_ID}) using the "
64
- "[diffusers PR #2](https://github.com/huggingface/diffusers-new-model-addition-ideogram/pull/2) "
65
- "branch, running on ZeroGPU."
66
- )
67
-
68
- with gr.Row():
69
- with gr.Column():
70
- prompt = gr.Textbox(
71
- label="Prompt",
72
- value="A photo of a cat holding a sign that says hello world",
73
- lines=3,
74
- )
75
- run = gr.Button("Generate", variant="primary")
76
- with gr.Accordion("Advanced", open=False):
77
- with gr.Row():
78
- width = gr.Slider(512, 2048, value=1024, step=64, label="Width")
79
- height = gr.Slider(512, 2048, value=1024, step=64, label="Height")
80
- steps = gr.Slider(8, 64, value=48, step=1, label="Inference steps")
81
- guidance = gr.Slider(
82
- 0.0, 15.0, value=0.0, step=0.1,
83
- label="Guidance scale (0 = recommended schedule: 7.0 → 3.0)",
84
- )
85
- with gr.Row():
86
- seed = gr.Number(label="Seed", value=0, precision=0)
87
- randomize = gr.Checkbox(label="Randomize seed", value=True)
88
- with gr.Column():
89
- out_image = gr.Image(label="Output", type="pil")
90
- out_seed = gr.Number(label="Seed used", interactive=False, precision=0)
91
-
92
- run.click(
93
- generate,
94
- inputs=[prompt, width, height, steps, guidance, seed, randomize],
95
- outputs=[out_image, out_seed],
96
- )
97
-
98
- demo.queue().launch()