|
import gradio as gr |
|
from diffusers import StableDiffusionImg2ImgPipeline |
|
import torch |
|
from PIL import Image |
|
|
|
|
|
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): |
|
|
|
image = input_image.resize((512, 512)).convert("RGB") |
|
|
|
|
|
output = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5) |
|
return output.images[0] |
|
|
|
|
|
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() |