Gemini899 commited on
Commit
55f9bde
·
verified ·
1 Parent(s): 2ab86fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -50,25 +50,18 @@ else:
50
 
51
  logging.info(f"Running on device={device} with dtype={torch_dtype}")
52
 
53
- # --- Model IDs & Token ---
54
- huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
55
- if not huggingface_token:
56
- print("ERROR: Environment variable HUGGINGFACE_TOKEN not set. Please add your token in Settings → Secrets.")
57
- sys.exit(1)
58
-
59
  flux_model_id = "black-forest-labs/FLUX.1-dev"
60
  controlnet_model_id = "jasperai/Flux.1-dev-Controlnet-Upscaler"
61
  local_model_dir = flux_model_id.split("/")[-1]
62
  pipe = None
63
 
64
- # --- Download & Load Models ---
65
  try:
66
- logging.info(f"Downloading {flux_model_id} with token…")
67
  model_path = snapshot_download(
68
  repo_id=flux_model_id,
69
  repo_type="model",
70
  local_dir=local_model_dir,
71
- use_auth_token=huggingface_token,
72
  ignore_patterns=["*.md", "*.gitattributes"],
73
  )
74
  logging.info(f"Downloaded base model to: {model_path}")
@@ -76,8 +69,7 @@ try:
76
  logging.info(f"Loading ControlNet: {controlnet_model_id}")
77
  controlnet = FluxControlNetModel.from_pretrained(
78
  controlnet_model_id,
79
- torch_dtype=torch_dtype,
80
- use_auth_token=huggingface_token
81
  ).to(device)
82
  logging.info("ControlNet loaded.")
83
 
@@ -85,18 +77,13 @@ try:
85
  pipe = FluxControlNetPipeline.from_pretrained(
86
  model_path,
87
  controlnet=controlnet,
88
- torch_dtype=torch_dtype,
89
- use_auth_token=huggingface_token
90
  ).to(device)
91
  logging.info("Pipeline ready.")
92
 
93
  except Exception as e:
94
  logging.error(f"Error loading models: {e}", exc_info=True)
95
- # Detect gated‐repo 401 by checking for “401” in the message
96
- if "401" in str(e):
97
- print(f"FATAL: Cannot access gated model {flux_model_id}. Have you accepted its license and set a valid HUGGINGFACE_TOKEN?")
98
- else:
99
- print(f"FATAL: model load failed: {e}")
100
  sys.exit(1)
101
 
102
  # --- Constants & Helpers ---
 
50
 
51
  logging.info(f"Running on device={device} with dtype={torch_dtype}")
52
 
53
+ # --- Model IDs & Download (no token) ---
 
 
 
 
 
54
  flux_model_id = "black-forest-labs/FLUX.1-dev"
55
  controlnet_model_id = "jasperai/Flux.1-dev-Controlnet-Upscaler"
56
  local_model_dir = flux_model_id.split("/")[-1]
57
  pipe = None
58
 
 
59
  try:
60
+ logging.info(f"Downloading base model: {flux_model_id}")
61
  model_path = snapshot_download(
62
  repo_id=flux_model_id,
63
  repo_type="model",
64
  local_dir=local_model_dir,
 
65
  ignore_patterns=["*.md", "*.gitattributes"],
66
  )
67
  logging.info(f"Downloaded base model to: {model_path}")
 
69
  logging.info(f"Loading ControlNet: {controlnet_model_id}")
70
  controlnet = FluxControlNetModel.from_pretrained(
71
  controlnet_model_id,
72
+ torch_dtype=torch_dtype
 
73
  ).to(device)
74
  logging.info("ControlNet loaded.")
75
 
 
77
  pipe = FluxControlNetPipeline.from_pretrained(
78
  model_path,
79
  controlnet=controlnet,
80
+ torch_dtype=torch_dtype
 
81
  ).to(device)
82
  logging.info("Pipeline ready.")
83
 
84
  except Exception as e:
85
  logging.error(f"Error loading models: {e}", exc_info=True)
86
+ print(f"FATAL: could not load models: {e}")
 
 
 
 
87
  sys.exit(1)
88
 
89
  # --- Constants & Helpers ---