Spaces:
Build error
Build error
Commit ·
9475cae
1
Parent(s): 893f88f
updated app.py
Browse files
app.py
CHANGED
|
@@ -31,19 +31,32 @@ CLASS_NAMES = [
|
|
| 31 |
'Tomato___healthy'
|
| 32 |
]
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
@st.cache_resource
|
| 35 |
def load_model():
|
| 36 |
"""Load the plant disease classification model from Hugging Face"""
|
| 37 |
model_url = "https://huggingface.co/ziadmostafa/EfficientNetB0-for-Plants-Diseases-Classification/resolve/main/densenet_model.keras"
|
| 38 |
response = requests.get(model_url)
|
| 39 |
if response.status_code == 200:
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return model
|
| 43 |
else:
|
| 44 |
st.error("Failed to load the model. Please check the URL.")
|
| 45 |
return None
|
| 46 |
|
|
|
|
| 47 |
def preprocess_image(img):
|
| 48 |
"""Preprocess image for model prediction using the specified preprocessing steps"""
|
| 49 |
img = img.resize((224, 224))
|
|
|
|
| 31 |
'Tomato___healthy'
|
| 32 |
]
|
| 33 |
|
| 34 |
+
import tempfile
|
| 35 |
+
import os
|
| 36 |
+
|
| 37 |
@st.cache_resource
|
| 38 |
def load_model():
|
| 39 |
"""Load the plant disease classification model from Hugging Face"""
|
| 40 |
model_url = "https://huggingface.co/ziadmostafa/EfficientNetB0-for-Plants-Diseases-Classification/resolve/main/densenet_model.keras"
|
| 41 |
response = requests.get(model_url)
|
| 42 |
if response.status_code == 200:
|
| 43 |
+
# Write the model to a temporary file and load from there
|
| 44 |
+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
| 45 |
+
tmp_file.write(response.content)
|
| 46 |
+
model_path = tmp_file.name
|
| 47 |
+
|
| 48 |
+
# Load the model from the file path
|
| 49 |
+
model = tf.keras.models.load_model(model_path, compile=False)
|
| 50 |
+
|
| 51 |
+
# Clean up the temporary file
|
| 52 |
+
os.remove(model_path)
|
| 53 |
+
|
| 54 |
return model
|
| 55 |
else:
|
| 56 |
st.error("Failed to load the model. Please check the URL.")
|
| 57 |
return None
|
| 58 |
|
| 59 |
+
|
| 60 |
def preprocess_image(img):
|
| 61 |
"""Preprocess image for model prediction using the specified preprocessing steps"""
|
| 62 |
img = img.resize((224, 224))
|