Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,13 +66,31 @@ def load_text_model():
|
|
| 66 |
# return model
|
| 67 |
@st.cache_resource
|
| 68 |
def load_image_model():
|
| 69 |
-
import os
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
model_path = hf_hub_download(
|
| 73 |
-
repo_id="Muniba930/image-detector",
|
| 74 |
-
filename="image_detector_v2.h5"
|
| 75 |
-
)
|
| 76 |
model = tf.keras.models.load_model(model_path)
|
| 77 |
return model
|
| 78 |
|
|
|
|
| 66 |
# return model
|
| 67 |
@st.cache_resource
|
| 68 |
def load_image_model():
|
| 69 |
+
import os
|
| 70 |
+
import tensorflow as tf
|
| 71 |
+
|
| 72 |
+
model_path = "/tmp/image_detector_v2.h5"
|
| 73 |
+
|
| 74 |
+
if not os.path.exists(model_path):
|
| 75 |
+
import requests
|
| 76 |
+
print("Downloading model...")
|
| 77 |
+
url = "https://huggingface.co/Muniba930/image-detector/resolve/main/image_detector_v2.h5?download=true"
|
| 78 |
+
|
| 79 |
+
with requests.get(url, stream=True) as r:
|
| 80 |
+
r.raise_for_status()
|
| 81 |
+
with open(model_path, "wb") as f:
|
| 82 |
+
for chunk in r.iter_content(chunk_size=8192):
|
| 83 |
+
f.write(chunk)
|
| 84 |
+
|
| 85 |
+
# Verify file size
|
| 86 |
+
size_mb = os.path.getsize(model_path) / (1024 * 1024)
|
| 87 |
+
print(f"Downloaded: {size_mb:.1f} MB")
|
| 88 |
+
|
| 89 |
+
if size_mb < 10:
|
| 90 |
+
os.remove(model_path)
|
| 91 |
+
st.error(f"Download failed — only {size_mb:.1f} MB received")
|
| 92 |
+
return None
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
model = tf.keras.models.load_model(model_path)
|
| 95 |
return model
|
| 96 |
|