File size: 1,074 Bytes
092aa85
 
84c269c
092aa85
 
84c269c
092aa85
84c269c
 
 
 
 
092aa85
 
84c269c
 
092aa85
84c269c
 
 
092aa85
84c269c
 
092aa85
 
84c269c
 
092aa85
 
84c269c
 
 
 
 
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
import gradio as gr
from diffusers import StableDiffusionImg2ImgPipeline
import torch
from PIL import Image

# Load pretrained stable-diffusion model
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5", 
    torch_dtype=torch.float16, 
    revision="fp16", 
    use_auth_token=True
).to("cuda" if torch.cuda.is_available() else "cpu")

def generate_thumbnail(prompt, input_image):
    # Resize image to 512x512
    image = input_image.resize((512, 512)).convert("RGB")
    
    # Generate image
    output = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5)
    return output.images[0]

# Gradio UI
demo = gr.Interface(
    fn=generate_thumbnail,
    inputs=[
        gr.Textbox(label="Enter your prompt (e.g., NOOB vs PRO Minecraft style)"),
        gr.Image(type="pil", label="Upload Background Image"),
    ],
    outputs=gr.Image(label="Generated Thumbnail"),
    title="AI Thumbnail Generator",
    description="Upload an image and enter your text to create a Minecraft-style YouTube thumbnail"
)

demo.launch()