EDR / app.py
Bagda's picture
Update app.py
84c269c verified
raw
history blame
1.07 kB
import gradio as gr
from diffusers import StableDiffusionImg2ImgPipeline
import torch
from PIL import Image
# Load pretrained stable-diffusion model
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):
# Resize image to 512x512
image = input_image.resize((512, 512)).convert("RGB")
# Generate image
output = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5)
return output.images[0]
# Gradio UI
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()