Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Load pre-trained model (no fine-tuning required)
|
8 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
9 |
+
"runwayml/stable-diffusion-v1-5",
|
10 |
+
torch_dtype=torch.float16
|
11 |
+
).to("cuda")
|
12 |
+
|
13 |
+
def generate_thumbnail(prompt, input_image):
|
14 |
+
if input_image is None or prompt.strip() == "":
|
15 |
+
return None
|
16 |
+
|
17 |
+
# Convert image to 512x512
|
18 |
+
input_image = input_image.resize((512, 512))
|
19 |
+
|
20 |
+
result = pipe(prompt=prompt, image=input_image, strength=0.75, guidance_scale=7.5).images[0]
|
21 |
+
return result
|
22 |
+
|
23 |
+
gr.Interface(
|
24 |
+
fn=generate_thumbnail,
|
25 |
+
inputs=[
|
26 |
+
gr.Textbox(label="Prompt (e.g. 'NOOB vs PRO Minecraft epic battle')"),
|
27 |
+
gr.Image(label="Background Image", type="pil")
|
28 |
+
],
|
29 |
+
outputs=gr.Image(label="Generated Thumbnail"),
|
30 |
+
title="🖼️ AI Thumbnail Generator (Stable Diffusion)",
|
31 |
+
description="Upload a background + write your prompt to generate a Minecraft-style thumbnail using Stable Diffusion v1.5"
|
32 |
+
).launch()
|