File size: 1,489 Bytes
6405f1a
 
 
 
0db4d23
 
6405f1a
0db4d23
6405f1a
 
0db4d23
 
6405f1a
0db4d23
 
6405f1a
 
 
 
 
 
 
 
 
 
0db4d23
6405f1a
0db4d23
6405f1a
 
 
 
 
0db4d23
6405f1a
0db4d23
 
6405f1a
 
 
 
0db4d23
6405f1a
 
 
0db4d23
 
6405f1a
0db4d23
6405f1a
 
0db4d23
6405f1a
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import torch
from PIL import Image

# We'll use the smallest available pipeline
from diffusers import DiffusionPipeline

# Load model (cached after first run)
@gr.cache()
def load_model():
    return DiffusionPipeline.from_pretrained(
        "OFA-Sys/small-stable-diffusion-v0",
        torch_dtype=torch.float16,
        safety_checker=None,
        use_safetensors=True
    ).to("cpu")

def generate_character(description, seed=42):
    try:
        pipe = load_model()
        
        torch.manual_seed(seed)
        with torch.inference_mode():
            image = pipe(
                prompt=f"pixel art character, {description}",
                num_inference_steps=15,
                guidance_scale=7.0,
                width=256,
                height=256
            ).images[0]
        
        return image
    except Exception as e:
        return f"Error: {str(e)}\nTry a simpler description."

with gr.Blocks(title="Lightweight Character Generator") as demo:
    gr.Markdown("# 🎨 Tiny Character Creator")
    
    with gr.Row():
        desc = gr.Textbox(
            label="Describe your character",
            placeholder="e.g., 'green alien with one eye'",
            max_lines=2
        )
    
    generate_btn = gr.Button("Generate Character")
    output = gr.Image(label="Your Character", shape=(256, 256))
    
    generate_btn.click(
        generate_character,
        inputs=desc,
        outputs=output
    )

demo.launch(debug=False)