Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,34 +70,16 @@ def load_image_model():
|
|
| 70 |
import tensorflow as tf
|
| 71 |
import requests
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
if os.path.exists(model_path):
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
# Debug: show what we're getting
|
| 85 |
-
content_type = r.headers.get("Content-Type", "unknown")
|
| 86 |
-
content_length = r.headers.get("Content-Length", "unknown")
|
| 87 |
-
st.write(f"Debug → Content-Type: {content_type}, Size: {content_length} bytes")
|
| 88 |
-
|
| 89 |
-
with open(model_path, "wb") as f:
|
| 90 |
-
for chunk in r.iter_content(chunk_size=8192):
|
| 91 |
-
f.write(chunk)
|
| 92 |
-
|
| 93 |
-
size_mb = os.path.getsize(model_path) / (1024 * 1024)
|
| 94 |
-
st.write(f"Debug → Downloaded file size: {size_mb:.2f} MB")
|
| 95 |
-
|
| 96 |
-
# Check first bytes to verify it's a real HDF5 file
|
| 97 |
-
with open(model_path, "rb") as f:
|
| 98 |
-
header = f.read(8)
|
| 99 |
-
st.write(f"Debug → File header bytes: {header.hex()}")
|
| 100 |
-
# Real HDF5 file starts with: 894844460d0a1a0a
|
| 101 |
|
| 102 |
model = tf.keras.models.load_model(model_path)
|
| 103 |
return model
|
|
|
|
| 70 |
import tensorflow as tf
|
| 71 |
import requests
|
| 72 |
|
| 73 |
+
# Use .keras extension so TF knows it's zip format
|
| 74 |
+
model_path = "/tmp/image_detector_v2.keras"
|
| 75 |
+
|
| 76 |
+
if not os.path.exists(model_path):
|
| 77 |
+
url = "https://huggingface.co/Muniba930/image-detector/resolve/main/image_detector_v2.h5?download=true"
|
| 78 |
+
with requests.get(url, stream=True, allow_redirects=True) as r:
|
| 79 |
+
r.raise_for_status()
|
| 80 |
+
with open(model_path, "wb") as f: # save as .keras not .h5
|
| 81 |
+
for chunk in r.iter_content(chunk_size=8192):
|
| 82 |
+
f.write(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
model = tf.keras.models.load_model(model_path)
|
| 85 |
return model
|