Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,34 @@
|
|
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
|
8 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
9 |
-
"runwayml/stable-diffusion-v1-5",
|
10 |
-
torch_dtype=torch.float16
|
11 |
-
|
|
|
|
|
12 |
|
13 |
def generate_thumbnail(prompt, input_image):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Convert image to 512x512
|
18 |
-
input_image = input_image.resize((512, 512))
|
19 |
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
|
|
24 |
fn=generate_thumbnail,
|
25 |
inputs=[
|
26 |
-
gr.Textbox(label="
|
27 |
-
gr.Image(
|
28 |
],
|
29 |
outputs=gr.Image(label="Generated Thumbnail"),
|
30 |
-
title="
|
31 |
-
description="Upload
|
32 |
-
)
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from diffusers import StableDiffusionImg2ImgPipeline
|
3 |
+
import torch
|
4 |
from PIL import Image
|
|
|
5 |
|
6 |
+
# Load pretrained stable-diffusion model
|
7 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
8 |
+
"runwayml/stable-diffusion-v1-5",
|
9 |
+
torch_dtype=torch.float16,
|
10 |
+
revision="fp16",
|
11 |
+
use_auth_token=True
|
12 |
+
).to("cuda" if torch.cuda.is_available() else "cpu")
|
13 |
|
14 |
def generate_thumbnail(prompt, input_image):
|
15 |
+
# Resize image to 512x512
|
16 |
+
image = input_image.resize((512, 512)).convert("RGB")
|
|
|
|
|
|
|
17 |
|
18 |
+
# Generate image
|
19 |
+
output = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5)
|
20 |
+
return output.images[0]
|
21 |
|
22 |
+
# Gradio UI
|
23 |
+
demo = gr.Interface(
|
24 |
fn=generate_thumbnail,
|
25 |
inputs=[
|
26 |
+
gr.Textbox(label="Enter your prompt (e.g., NOOB vs PRO Minecraft style)"),
|
27 |
+
gr.Image(type="pil", label="Upload Background Image"),
|
28 |
],
|
29 |
outputs=gr.Image(label="Generated Thumbnail"),
|
30 |
+
title="AI Thumbnail Generator",
|
31 |
+
description="Upload an image and enter your text to create a Minecraft-style YouTube thumbnail"
|
32 |
+
)
|
33 |
+
|
34 |
+
demo.launch()
|