daniissac commited on
Commit
ddd1d55
·
verified ·
1 Parent(s): b214f93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -1,31 +1,25 @@
1
  import gradio as gr
2
  import torch
3
  from diffusers import StableDiffusionPipeline
4
- from PIL import Image
5
 
6
- # Load the pre-trained Ghibli-Diffusion model
7
  model_id = "nitrosocke/Ghibli-Diffusion"
8
- pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
9
- pipeline.to("cuda") # Ensure GPU acceleration
10
 
11
- def generate_ghibli_portrait(image):
12
- # Convert input image to PIL format
13
- input_image = Image.open(image).convert("RGB").resize((512, 512))
14
-
15
- # Generate image using the model
16
- prompt = "Ghibli-style portrait of a person, highly detailed, soft lighting"
17
- result = pipeline(prompt=prompt, image=input_image).images[0]
18
-
19
  return result
20
 
21
- # Gradio UI
22
- demo = gr.Interface(
23
- fn=generate_ghibli_portrait,
24
- inputs=gr.Image(type="file", label="Upload your photo"),
25
- outputs=gr.Image(label="Ghibli-style Portrait"),
26
  title="Studio Ghibli Portrait Generator",
27
- description="Upload your photo to generate a Ghibli-style portrait using AI."
28
  )
29
 
30
- if __name__ == "__main__":
31
- demo.launch()
 
1
  import gradio as gr
2
  import torch
3
  from diffusers import StableDiffusionPipeline
 
4
 
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
  model_id = "nitrosocke/Ghibli-Diffusion"
 
 
7
 
8
+ # Load the model
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if device == "cuda" else torch.float32)
10
+ pipe.to(device)
11
+
12
+ def generate_ghibli_style(image):
13
+ prompt = "Studio Ghibli style portrait of a person, highly detailed, beautiful colors"
14
+ result = pipe(prompt, init_image=image, strength=0.75).images[0]
 
15
  return result
16
 
17
+ iface = gr.Interface(
18
+ fn=generate_ghibli_style,
19
+ inputs=gr.Image(type="pil"),
20
+ outputs=gr.Image(),
 
21
  title="Studio Ghibli Portrait Generator",
22
+ description="Upload a photo, and this AI will transform it into a Ghibli-style portrait!"
23
  )
24
 
25
+ iface.launch()