BunkerMinecraft commited on
Commit
d1ba352
·
verified ·
1 Parent(s): 44b3a85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import tensorflow as tf
2
  from tensorflow.keras import layers, models, regularizers
3
  import json
@@ -27,8 +28,30 @@ model = models.Sequential([
27
  layers.Dense(6, activation='softmax')
28
  ])
29
 
30
- # ---- Load trained weights ----
31
- model.load_weights("model_weights.h5")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  # ---- Preprocess image ----
34
  def preprocess(image: Image.Image):
 
1
+ from huggingface_hub import hf_hub_download
2
  import tensorflow as tf
3
  from tensorflow.keras import layers, models, regularizers
4
  import json
 
28
  layers.Dense(6, activation='softmax')
29
  ])
30
 
31
+ # ---- Load trained weights (pointer-safe) ----
32
+ WEIGHTS_LOCAL = "model_weights.h5"
33
+ MODEL_REPO_ID = "BunkerMinecraft/neurecaiv2" # change to your model repo
34
+
35
+ def _is_pointer(path: str) -> bool:
36
+ if not os.path.exists(path) or os.path.getsize(path) < 1024:
37
+ try:
38
+ with open(path, "rb") as f:
39
+ head = f.read(200)
40
+ return (b"git-lfs" in head) or (b"xet" in head)
41
+ except Exception:
42
+ return True
43
+ return False
44
+
45
+ if _is_pointer(WEIGHTS_LOCAL):
46
+ WEIGHTS_LOCAL = hf_hub_download(
47
+ repo_id=MODEL_REPO_ID,
48
+ filename="model_weights.h5",
49
+ repo_type="model"
50
+ )
51
+
52
+ model.load_weights(WEIGHTS_LOCAL)
53
+ print(f"Loaded weights from: {WEIGHTS_LOCAL}")
54
+
55
 
56
  # ---- Preprocess image ----
57
  def preprocess(image: Image.Image):