daniissac commited on
Commit
2562825
·
verified ·
1 Parent(s): d916ac2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()