SUN / app.py
Bagda's picture
Update app.py
53a1f24 verified
raw
history blame
1.48 kB
import gradio as gr
from PIL import Image
from utils import generate_thumbnail
def process(image, text, font_size, position, text_color):
result = generate_thumbnail(image, text, font_size=font_size, position=position, text_color=text_color)
return result
demo = gr.Interface(
fn=process,
inputs=[
gr.Image(type="pil", label="Upload Background Image"),
gr.Textbox(label="Thumbnail Text"),
gr.Slider(20, 100, step=5, value=60, label="Font Size"),
gr.Radio(["top", "center", "bottom"], label="Text Position", value="bottom"),
gr.ColorPicker(label="Text Color", value="#FFFFFF"),
],
outputs=gr.Image(label="Generated Thumbnail"),
title="🖼️ AI Thumbnail Generator",
description="Upload an image and generate a custom thumbnail with your text.",
allow_flagging="never"
)
if __name__ == "__main__":
demo.launch()
from diffusers import StableDiffusionPipeline
import torch
# Load model from Hugging Face Hub
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", # You can use another model if needed
torch_dtype=torch.float16,
use_safetensors=True,
revision="fp16"
)
# Move to GPU if available
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
# Generate an image
prompt = "A Minecraft player standing on a hill during sunset, pixel art style"
image = pipe(prompt).images[0]
# Save the image
image.save("minecraft_thumbnail.png")