Spaces:
Runtime error
Runtime error
Add cached gr.Examples (lazy) + generate defaults + fp8 link; remove stale tmp/ and __pycache__/
Browse filesFiles changed (3)
- __pycache__/app.cpython-312.pycDeleted
- app.py+24-1
- tmp/ideogram4_space/app.pyDeleted-98
126 unmodified lines12712812913013113213365 unmodified lines19920020120220320419 unmodified lines224225226227228229126 unmodified lines@spaces.GPU(duration=240, size="xlarge")def generate(prompt, mode, upsampler, width, height, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):t_enter = time.perf_counter()if randomize_seed or seed < 0:seed = random.randint(0, MAX_SEED)65 unmodified lines"Ideogram's first open-weights model — a 9.3B-parameter text-to-image foundation model at the ""forefront of design, with best-in-class text rendering.\n\n""[Model](https://huggingface.co/ideogram-ai/ideogram-4-nf4) · ""[Blog](https://ideogram.ai/blog/ideogram-4.0/)")19 unmodified linesout_image = gr.Image(label="Output", type="pil")out_caption = gr.JSON(label="Caption fed to the model (upsampled when enabled)")run.click(generate,inputs=[prompt, mode, upsampler, width, height, seed, randomize],126 unmodified lines12712812913013113213313413513613713813914014114265 unmodified lines20820921021121221321419 unmodified lines234235236237238239240241242243244245246247248249250251252126 unmodified lines@spaces.GPU(duration=240, size="xlarge")def generate(prompt,mode="Default · 20 steps",upsampler=UPSAMPLERS[0],width=1024,height=1024,seed=0,randomize_seed=False,progress=gr.Progress(track_tqdm=True),):t_enter = time.perf_counter()if randomize_seed or seed < 0:seed = random.randint(0, MAX_SEED)65 unmodified lines"Ideogram's first open-weights model — a 9.3B-parameter text-to-image foundation model at the ""forefront of design, with best-in-class text rendering.\n\n""[Model](https://huggingface.co/ideogram-ai/ideogram-4-nf4) · ""[Model (fp8)](https://huggingface.co/ideogram-ai/ideogram-4-fp8) · ""[Blog](https://ideogram.ai/blog/ideogram-4.0/)")19 unmodified linesout_image = gr.Image(label="Output", type="pil")out_caption = gr.JSON(label="Caption fed to the model (upsampled when enabled)")gr.Examples(examples=[["a ginger cat wearing a tiny wizard hat reading a spellbook"],["an isometric illustration of a tiny city floating in the clouds"],["a golden retriever on a skateboard"],],inputs=[prompt],outputs=[out_image, seed, out_caption],fn=generate,cache_examples=True,cache_mode="lazy",)run.click(generate,inputs=[prompt, mode, upsampler, width, height, seed, randomize],
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798import osimport sys
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
# Use the bundled diffusers source (PR #2: huggingface/diffusers-new-model-addition-ideogram)._HERE = os.path.dirname(os.path.abspath(__file__))sys.path.insert(0, os.path.join(_HERE, "diffusers_src", "src"))
import random
import spacesimport torchimport gradio as grfrom diffusers import Ideogram4Pipeline
MODEL_ID = "diffusers-internal-dev/ideogram-4-nf4"
pipe = Ideogram4Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)pipe.to("cuda")
MAX_SEED = 2**31 - 1
@spaces.GPU(duration=180)def generate( prompt: str, width: int, height: int, num_inference_steps: int, guidance_scale: float, seed: int, randomize_seed: bool, progress=gr.Progress(track_tqdm=True),): if randomize_seed or seed < 0: seed = random.randint(0, MAX_SEED) generator = torch.Generator(device="cuda").manual_seed(int(seed))
steps = int(num_inference_steps) kwargs = dict( prompt=prompt, width=int(width), height=int(height), num_inference_steps=steps, generator=generator, ) if guidance_scale > 0: kwargs["guidance_scale"] = float(guidance_scale) kwargs["guidance_schedule"] = None else: # PR default is len 48 (7.0 x45 + 3.0 x3); rebuild it for any step count. tail = min(3, max(0, steps - 1)) kwargs["guidance_schedule"] = (7.0,) * (steps - tail) + (3.0,) * tail
image = pipe(**kwargs).images[0] return image, seed
with gr.Blocks(title="Ideogram 4 (NF4) — diffusers preview") as demo: gr.Markdown( "## Ideogram 4 (NF4) — diffusers preview\n" f"Private demo of [`{MODEL_ID}`](https://huggingface.co/{MODEL_ID}) using the " "[diffusers PR #2](https://github.com/huggingface/diffusers-new-model-addition-ideogram/pull/2) " "branch, running on ZeroGPU." )
with gr.Row(): with gr.Column(): prompt = gr.Textbox( label="Prompt", value="A photo of a cat holding a sign that says hello world", lines=3, ) run = gr.Button("Generate", variant="primary") with gr.Accordion("Advanced", open=False): with gr.Row(): width = gr.Slider(512, 2048, value=1024, step=64, label="Width") height = gr.Slider(512, 2048, value=1024, step=64, label="Height") steps = gr.Slider(8, 64, value=48, step=1, label="Inference steps") guidance = gr.Slider( 0.0, 15.0, value=0.0, step=0.1, label="Guidance scale (0 = recommended schedule: 7.0 → 3.0)", ) with gr.Row(): seed = gr.Number(label="Seed", value=0, precision=0) randomize = gr.Checkbox(label="Randomize seed", value=True) with gr.Column(): out_image = gr.Image(label="Output", type="pil") out_seed = gr.Number(label="Seed used", interactive=False, precision=0)
run.click( generate, inputs=[prompt, width, height, steps, guidance, seed, randomize], outputs=[out_image, out_seed], )
demo.queue().launch()__pycache__/app.cpython-312.pycDeleted
app.py+24-1
tmp/ideogram4_space/app.pyDeleted-98