nimraaaajhduksy commited on
Commit
131839e
Β·
verified Β·
1 Parent(s): 8f9eca2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -3,7 +3,7 @@ from PIL import Image
3
  import numpy as np
4
  import torch
5
  import os
6
- from diffusers import DiffusionPipeline # Changed: Use DiffusionPipeline instead
7
  from diffusers.utils import load_image
8
  from huggingface_hub import HfApi, login
9
  from huggingface_hub.utils import HfHubHTTPError
@@ -35,15 +35,23 @@ else:
35
  # ───── Load FLUX-Kontext Pipeline ─────
36
  device = "cuda" if torch.cuda.is_available() else "cpu"
37
 
38
- # Fixed: Load the custom pipeline correctly
39
- pipe = DiffusionPipeline.from_pretrained(
40
- "HighCWu/FLUX.1-Kontext-dev-bnb-hqq-4bit",
41
- torch_dtype=torch.bfloat16,
42
- custom_pipeline="FluxKontextPipeline", # This loads the custom pipeline
43
- trust_remote_code=True # Added: Required for custom pipelines
44
- )
 
 
 
 
 
 
 
 
 
45
  pipe.to(device)
46
- print("βœ… FLUX-Kontext pipeline loaded")
47
 
48
  # ───── Load YOLOv8 Segmentation Model ─────
49
  yolo = YOLO('yolov8s-seg.pt') # can be replaced with your own weights
 
3
  import numpy as np
4
  import torch
5
  import os
6
+ from diffusers import FluxKontextPipeline # Fixed: Import the correct pipeline
7
  from diffusers.utils import load_image
8
  from huggingface_hub import HfApi, login
9
  from huggingface_hub.utils import HfHubHTTPError
 
35
  # ───── Load FLUX-Kontext Pipeline ─────
36
  device = "cuda" if torch.cuda.is_available() else "cpu"
37
 
38
+ # Try the quantized version first, fallback to official if needed
39
+ try:
40
+ pipe = FluxKontextPipeline.from_pretrained(
41
+ "HighCWu/FLUX.1-Kontext-dev-bnb-hqq-4bit",
42
+ torch_dtype=torch.bfloat16,
43
+ )
44
+ print("βœ… FLUX-Kontext quantized pipeline loaded")
45
+ except Exception as e:
46
+ print(f"⚠️ Quantized model failed: {e}")
47
+ print("πŸ“₯ Falling back to official model...")
48
+ pipe = FluxKontextPipeline.from_pretrained(
49
+ "black-forest-labs/FLUX.1-Kontext-dev",
50
+ torch_dtype=torch.bfloat16,
51
+ )
52
+ print("βœ… FLUX-Kontext official pipeline loaded")
53
+
54
  pipe.to(device)
 
55
 
56
  # ───── Load YOLOv8 Segmentation Model ─────
57
  yolo = YOLO('yolov8s-seg.pt') # can be replaced with your own weights