daniissac commited on
Commit
5af654c
·
verified ·
1 Parent(s): 1b4f79a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -5,13 +5,15 @@ from diffusers import StableDiffusionPipeline
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 = "ghibli style portrait"
14
- result = pipe(prompt, init_image=image, strength=0.75, guidance_scale=7.0, num_inference_steps=30).images[0]
 
15
  return result
16
 
17
  iface = gr.Interface(
 
5
  device = "cuda" if torch.cuda.is_available() else "cpu"
6
  model_id = "nitrosocke/Ghibli-Diffusion"
7
 
8
+ # Load the model once and keep it in memory
9
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if device == "cuda" else torch.float32)
10
  pipe.to(device)
11
+ pipe.enable_attention_slicing() # Optimize memory usage
12
 
13
  def generate_ghibli_style(image):
14
  prompt = "ghibli style portrait"
15
+ with torch.inference_mode(): # Disables gradient calculations for faster inference
16
+ result = pipe(prompt, image=image, strength=0.6, guidance_scale=6.5, num_inference_steps=25).images[0] # Reduced steps & optimized scale
17
  return result
18
 
19
  iface = gr.Interface(