StuffTestingWorking commited on
Commit
ea7909b
·
verified ·
1 Parent(s): f4e1a78

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionImg2ImgPipeline
2
+ from PIL import Image
3
+ import torch
4
+ import gradio as gr
5
+
6
+ # Load the model
7
+ model_id = "lavaman131/cartoonify"
8
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
9
+ pipe.to("cpu")
10
+
11
+ # Define the function that processes the image
12
+ def cartoonify(image):
13
+ image = image.convert("RGB").resize((512, 512))
14
+ prompt = "A cartoon version of this image, pixar disney style"
15
+ output = pipe(prompt=prompt, image=image, strength=0.5, guidance_scale=6).images[0]
16
+ return output
17
+
18
+ # Set up Gradio interface
19
+ interface = gr.Interface(
20
+ fn=cartoonify,
21
+ inputs=gr.Image(type="pil", label="Upload your photo"),
22
+ outputs=gr.Image(label="Cartoonified image"),
23
+ title="Cartoonify Your Image!",
24
+ description="Upload a photo and get a cartoon version in a Pixar/Disney style."
25
+ )
26
+
27
+ # Launch the app
28
+ interface.launch()