syeda-Rija20 commited on
Commit
25f5b89
Β·
verified Β·
1 Parent(s): 5457494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -23
app.py CHANGED
@@ -463,30 +463,23 @@ def load_text_model():
463
 
464
  @st.cache_resource(show_spinner=False)
465
  def load_image_model():
466
- filenames_to_try = [
467
- "image_detector_clean.keras", # ← clean model first
468
- "image_detector_v2.keras", # ← fallbacks
469
- "image_detector_v2.h5",
470
- ]
471
- path = None
472
- for fname in filenames_to_try:
473
- try:
474
- path = hf_hub_download(
475
- repo_id="syeda-Rija20/image-detector",
476
- filename=fname
477
- )
478
- break
479
- except Exception:
480
- continue
481
-
482
- if path is None:
483
- raise RuntimeError(
484
- "Could not download image model from HuggingFace Hub. "
485
- "Check that 'syeda-Rija20/image-detector' is public and the file exists."
486
- )
487
-
488
  import keras
489
- model = keras.saving.load_model(path, compile=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  return model
491
 
492
  # ─────────────────────────────────────────────
 
463
 
464
  @st.cache_resource(show_spinner=False)
465
  def load_image_model():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  import keras
467
+ import json
468
+
469
+ config_path = hf_hub_download(
470
+ repo_id="syeda-Rija20/image-detector",
471
+ filename="model_config.json"
472
+ )
473
+ weights_path = hf_hub_download(
474
+ repo_id="syeda-Rija20/image-detector",
475
+ filename="image_detector_clean.weights.h5"
476
+ )
477
+
478
+ with open(config_path) as f:
479
+ config = f.read()
480
+
481
+ model = keras.models.model_from_json(config)
482
+ model.load_weights(weights_path)
483
  return model
484
 
485
  # ─────────────────────────────────────────────