File size: 1,022 Bytes
092aa85 84c269c 092aa85 ab0b7fb 092aa85 9e13de8 ab0b7fb 9e13de8 ab0b7fb 9e13de8 ab0b7fb 9e13de8 092aa85 84c269c ab0b7fb 092aa85 ab0b7fb 9e13de8 092aa85 9e13de8 ab0b7fb |
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 |
import gradio as gr
from diffusers import StableDiffusionImg2ImgPipeline
import torch
from PIL import Image
# Load pretrained model
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 # Use secret token
)
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
# Main function
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]
# Gradio UI
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() |