Spaces:
Build error
Build error
Commit ·
94d75b0
1
Parent(s): 4fe231a
Fix FluxFillPipeline and accelerate
Browse files- app.py +9 -24
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
-
from diffusers import
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
import cv2
|
|
@@ -26,29 +26,13 @@ else:
|
|
| 26 |
|
| 27 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
feature_extractor=None, # Disable if missing
|
| 37 |
-
image_encoder=None, # Disable if missing
|
| 38 |
-
).to(device)
|
| 39 |
-
pipe.enable_model_cpu_offload()
|
| 40 |
-
except ValueError as e:
|
| 41 |
-
print(
|
| 42 |
-
f"Pipeline loading failed due to missing components: {e}. Falling back to compatible model."
|
| 43 |
-
)
|
| 44 |
-
# Fallback to a fully supported inpainting model
|
| 45 |
-
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 46 |
-
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16
|
| 47 |
-
).to(device)
|
| 48 |
-
pipe.enable_model_cpu_offload()
|
| 49 |
-
except Exception as e:
|
| 50 |
-
print(f"Unexpected error loading pipeline: {e}")
|
| 51 |
-
raise
|
| 52 |
|
| 53 |
|
| 54 |
def inpaint(
|
|
@@ -70,6 +54,7 @@ def inpaint(
|
|
| 70 |
mask_image=mask,
|
| 71 |
num_inference_steps=50,
|
| 72 |
guidance_scale=7.5,
|
|
|
|
| 73 |
).images[0]
|
| 74 |
return output
|
| 75 |
except Exception as e:
|
|
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
+
from diffusers import FluxFillPipeline
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
import cv2
|
|
|
|
| 26 |
|
| 27 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 28 |
|
| 29 |
+
# Load the correct pipeline
|
| 30 |
+
pipe = FluxFillPipeline.from_pretrained(
|
| 31 |
+
"black-forest-labs/FLUX.1-Fill-dev",
|
| 32 |
+
torch_dtype=torch.bfloat16,
|
| 33 |
+
token=hf_token,
|
| 34 |
+
).to(device)
|
| 35 |
+
pipe.enable_model_cpu_offload()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
def inpaint(
|
|
|
|
| 54 |
mask_image=mask,
|
| 55 |
num_inference_steps=50,
|
| 56 |
guidance_scale=7.5,
|
| 57 |
+
max_sequence_length=512,
|
| 58 |
).images[0]
|
| 59 |
return output
|
| 60 |
except Exception as e:
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ transformers
|
|
| 5 |
gradio
|
| 6 |
opencv-python-headless
|
| 7 |
numpy
|
| 8 |
-
huggingface_hub
|
|
|
|
|
|
| 5 |
gradio
|
| 6 |
opencv-python-headless
|
| 7 |
numpy
|
| 8 |
+
huggingface_hub
|
| 9 |
+
accelerate
|