File size: 1,177 Bytes
6d3dbcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
from PIL import Image, ImageDraw, ImageFont
from diffusers import StableDiffusionInstructPix2PixPipeline
import torch

# Load the model (once)
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
    "timbrooks/instruct-pix2pix",
    torch_dtype=torch.float16,
    safety_checker=None
).to("cuda")

def stylize(image: Image.Image, quote: str) -> Image.Image:
    # Step 1: Stylize with instruct-pix2pix
    edited_image = pipe(image=image, prompt="neon filter", image_guidance_scale=1.5).images[0]

    # Step 2: Overlay text
    draw = ImageDraw.Draw(edited_image)
    font = ImageFont.load_default()
    width, height = edited_image.size
    draw.text((10, height - 40), quote, font=font, fill="cyan")

    return edited_image

interface = gr.Interface(
    fn=stylize,
    inputs=[
        gr.Image(type="pil", label="Upload Your Photo"),
        gr.Textbox(label="Your Quote")
    ],
    outputs=gr.Image(type="pil", label="Neon Image"),
    title="Neon Image Stylizer",
    description="Upload an image of your business or product and add your quote. We'll stylize it with a neon effect!"
)

if __name__ == "__main__":
    interface.launch()