c4dr commited on
Commit
cedc5fc
·
verified ·
1 Parent(s): 91e8eac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionImg2ImgPipeline
4
+ from PIL import Image
5
+
6
+ # Initialize pipeline
7
+ dtype = torch.float16 if torch.cuda.is_available() else torch.float32
8
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
9
+ "nitrosocke/Ghibli-Diffusion",
10
+ torch_dtype=dtype
11
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
12
+
13
+ def process_image(input_img):
14
+ if input_img is None:
15
+ return None
16
+
17
+ # Convert and resize input
18
+ input_img = input_img.convert("RGB").resize((512, 512))
19
+
20
+ # Generate output
21
+ result = pipe(
22
+ prompt="ghibli style, studio ghibli, anime art",
23
+ image=input_img,
24
+ strength=0.7,
25
+ guidance_scale=10
26
+ ).images[0]
27
+
28
+ return result
29
+
30
+ # Create Gradio interface
31
+ demo = gr.Interface(
32
+ fn=process_image,
33
+ inputs=gr.Image(type="pil"),
34
+ outputs=gr.Image(type="pil"),
35
+ title="🎨 Ghibli Style Transfer",
36
+ description="Upload an image to transform it into Studio Ghibli style artwork"
37
+ )
38
+
39
+ demo.launch()