|
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, |
|
use_auth_token=True |
|
) |
|
|
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu" |
|
pipe = pipe.to(device) |
|
|
|
|
|
def generate_thumbnail(prompt, input_image): |
|
image = input_image.resize((512, 512)).convert("RGB") |
|
result = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5) |
|
return result.images[0] |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_thumbnail, |
|
inputs=[ |
|
gr.Textbox(label="Thumbnail Prompt (e.g., 'NOOB vs PRO in Minecraft')"), |
|
gr.Image(type="pil", label="Upload Background Image") |
|
], |
|
outputs=gr.Image(label="Generated Thumbnail"), |
|
title="🖼️ AI Thumbnail Generator", |
|
description="Upload a background image and enter a thumbnail prompt to generate your own YouTube-style thumbnail using Stable Diffusion!" |
|
) |
|
|
|
interface.launch() |