EDR / app.py
Bagda's picture
Update app.py
ab0b7fb verified
raw
history blame
1.02 kB
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()