|
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 if torch.cuda.is_available() else torch.float32, |
|
use_auth_token=True |
|
) |
|
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
def generate_thumbnail(prompt, image): |
|
image = image.resize((512, 512)).convert("RGB") |
|
result = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5) |
|
return result.images[0] |
|
|
|
|
|
gr.Interface( |
|
fn=generate_thumbnail, |
|
inputs=[ |
|
gr.Textbox(label="Prompt (e.g. 'Minecraft NOOB vs PRO battle')"), |
|
gr.Image(type="pil", label="Upload Background Image") |
|
], |
|
outputs=gr.Image(label="Generated Thumbnail"), |
|
title="🖼️ AI Thumbnail Generator", |
|
description="Enter prompt and image to create YouTube-style thumbnails" |
|
).launch() |