Spaces:
Running
Running
File size: 904 Bytes
ea7909b |
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 |
from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image
import torch
import gradio as gr
# Load the model
model_id = "lavaman131/cartoonify"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.to("cpu")
# Define the function that processes the image
def cartoonify(image):
image = image.convert("RGB").resize((512, 512))
prompt = "A cartoon version of this image, pixar disney style"
output = pipe(prompt=prompt, image=image, strength=0.5, guidance_scale=6).images[0]
return output
# Set up Gradio interface
interface = gr.Interface(
fn=cartoonify,
inputs=gr.Image(type="pil", label="Upload your photo"),
outputs=gr.Image(label="Cartoonified image"),
title="Cartoonify Your Image!",
description="Upload a photo and get a cartoon version in a Pixar/Disney style."
)
# Launch the app
interface.launch()
|