Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,28 +68,36 @@ def load_text_model():
|
|
| 68 |
def load_image_model():
|
| 69 |
import os
|
| 70 |
import tensorflow as tf
|
|
|
|
| 71 |
|
| 72 |
model_path = "/tmp/image_detector_v2.h5"
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
for chunk in r.iter_content(chunk_size=8192):
|
| 83 |
-
f.write(chunk)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
model = tf.keras.models.load_model(model_path)
|
| 95 |
return model
|
|
|
|
| 68 |
def load_image_model():
|
| 69 |
import os
|
| 70 |
import tensorflow as tf
|
| 71 |
+
import requests
|
| 72 |
|
| 73 |
model_path = "/tmp/image_detector_v2.h5"
|
| 74 |
|
| 75 |
+
# Always re-download (remove old corrupted file)
|
| 76 |
+
if os.path.exists(model_path):
|
| 77 |
+
os.remove(model_path)
|
| 78 |
+
|
| 79 |
+
url = "https://huggingface.co/Muniba930/image-detector/resolve/main/image_detector_v2.h5?download=true"
|
| 80 |
+
|
| 81 |
+
with requests.get(url, stream=True, allow_redirects=True) as r:
|
| 82 |
+
r.raise_for_status()
|
|
|
|
|
|
|
| 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
|