|
import gradio as gr |
|
import torch |
|
from diffusers import StableDiffusionImg2ImgPipeline |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
pipe = StableDiffusionImg2ImgPipeline.from_pretrained( |
|
"runwayml/stable-diffusion-v1-5", |
|
torch_dtype=torch.float16 |
|
).to("cuda") |
|
|
|
def generate_thumbnail(prompt, input_image): |
|
if input_image is None or prompt.strip() == "": |
|
return None |
|
|
|
|
|
input_image = input_image.resize((512, 512)) |
|
|
|
result = pipe(prompt=prompt, image=input_image, strength=0.75, guidance_scale=7.5).images[0] |
|
return result |
|
|
|
gr.Interface( |
|
fn=generate_thumbnail, |
|
inputs=[ |
|
gr.Textbox(label="Prompt (e.g. 'NOOB vs PRO Minecraft epic battle')"), |
|
gr.Image(label="Background Image", type="pil") |
|
], |
|
outputs=gr.Image(label="Generated Thumbnail"), |
|
title="🖼️ AI Thumbnail Generator (Stable Diffusion)", |
|
description="Upload a background + write your prompt to generate a Minecraft-style thumbnail using Stable Diffusion v1.5" |
|
).launch() |