Skip to content

Gradio UI implementation Guide #16

@Astroburner

Description

@Astroburner
  1. pip install gradio
  2. start via cmd python
  3. Insert

import gradio as gr
import torch
from hyimage.diffusion.pipelines.hunyuanimage_pipeline import HunyuanImagePipeline

Modell load

model_name = "hunyuanimage-v2.1"
pipe = HunyuanImagePipeline.from_pretrained(model_name=model_name, torch_dtype='bf16')
pipe = pipe.to("cuda")

Function with Gradio

def generate(prompt, width=1024, height=1024, steps=20, guidance=3.5, seed=42):
image = pipe(
prompt=prompt,
width=width,
height=height,
num_inference_steps=steps,
guidance_scale=guidance,
shift=5,
seed=seed,
)
return image

Gradio UI

demo = gr.Interface(
fn=generate,
inputs=[
gr.Textbox(label="Prompt", lines=5, placeholder="Schreibe hier deinen Prompt..."),
gr.Slider(512, 2048, value=1024, step=64, label="Width"),
gr.Slider(512, 2048, value=1024, step=64, label="Height"),
gr.Slider(1, 50, value=20, step=1, label="Steps"),
gr.Slider(1.0, 10.0, value=3.5, step=0.1, label="Guidance Scale"),
gr.Number(value=42, label="Seed"),
],
outputs=gr.Image(type="pil", label="Generated Image"),
title="HunyuanImage v2.1 Generator",
description="Creat images with your prompt in HunyuanImage."
)

demo.launch(server_name="0.0.0.0", server_port=8188)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions