Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
| 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(
|