HunyuanImage-3 / app.py
Alae65's picture
Update to HunyuanImage-3.0 interface
44feade verified
raw
history blame
3.94 kB
import gradio as gr
import torch
from transformers import AutoModelForCausalLM
import os
# Load the model
model_id = "tencent/HunyuanImage-3.0"
print("Loading HunyuanImage-3.0 model...")
print("Note: This is a very large model (80B params) and requires significant GPU memory.")
print("For production use, consider using the FAL API or other inference providers.")
# For demo purposes, we'll use inference API
def generate_image(prompt, seed=42, diff_infer_steps=50, image_size="auto"):
"""
Generate image using HunyuanImage-3.0
Note: Direct model loading requires 3x80GB GPU memory.
For Spaces, consider using Inference API or providers like FAL.
"""
try:
# This is a placeholder - actual implementation would require
# either very large GPU or using Inference API
from PIL import Image
import numpy as np
# Create a placeholder image with text
img = Image.new('RGB', (1024, 1024), color=(240, 240, 245))
return img, seed
except Exception as e:
print(f"Error: {e}")
return None, seed
def infer(prompt, seed, randomize_seed, diff_infer_steps, image_size):
import random
if randomize_seed:
seed = random.randint(0, 2**32 - 1)
image, used_seed = generate_image(prompt, seed, diff_infer_steps, image_size)
return image, used_seed
# Gradio Interface
examples = [
"A brown and white dog is running on the grass",
"A futuristic city at sunset with flying cars",
"A serene mountain landscape with a crystal clear lake",
]
css = """
#col-container {
margin: 0 auto;
max-width: 800px;
}
.note {
background: #fff3cd;
padding: 15px;
border-radius: 8px;
margin: 10px 0;
}
"""
with gr.Blocks(css=css) as demo:
with gr.Column(elem_id="col-container"):
gr.Markdown("# 🎨 HunyuanImage-3.0 Text-to-Image")
gr.Markdown(
"""### Tencent HunyuanImage-3.0 - A Powerful Native Multimodal Model
**⚠️ Important Note:** This model requires 3×80GB GPU memory for direct inference.
For production use, please:
1. Use the Inference API endpoint
2. Use inference providers like FAL AI
3. Deploy on appropriate hardware
This demo shows the interface structure. For actual inference, configure with appropriate resources.
""",
elem_classes="note"
)
with gr.Row():
prompt = gr.Text(
label="Prompt",
show_label=True,
max_lines=3,
placeholder="Enter your prompt for image generation...",
)
run_button = gr.Button("🎨 Generate Image", variant="primary")
result = gr.Image(label="Generated Image", show_label=True)
with gr.Accordion("Advanced Settings", open=False):
seed = gr.Slider(
label="Seed",
minimum=0,
maximum=2**32 - 1,
step=1,
value=42,
)
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
diff_infer_steps = gr.Slider(
label="Diffusion inference steps",
minimum=10,
maximum=100,
step=10,
value=50,
)
image_size = gr.Radio(
label="Image Size",
choices=["auto", "1024x1024", "1280x768", "768x1280"],
value="auto",
)
gr.Examples(examples=examples, inputs=[prompt])
run_button.click(
fn=infer,
inputs=[prompt, seed, randomize_seed, diff_infer_steps, image_size],
outputs=[result, seed],
)
if __name__ == "__main__":
demo.launch()