Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ def get_transform():
|
|
59 |
|
60 |
# Define function to load model
|
61 |
@st.cache_resource
|
62 |
-
def load_model(model_path="
|
63 |
# Try to find model_info.json to determine which model architecture to use
|
64 |
model_dir = os.path.dirname(model_path)
|
65 |
model_info_path = os.path.join(model_dir, "model_info.json")
|
@@ -290,41 +290,36 @@ def main():
|
|
290 |
with upload_container:
|
291 |
uploaded_file = st.file_uploader("Choose a leaf image to analyze", type=["jpg", "jpeg", "png"])
|
292 |
|
293 |
-
# Add
|
294 |
-
st.markdown("<h3>Or
|
295 |
-
|
296 |
|
297 |
-
#
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
]
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
if
|
310 |
-
|
|
|
|
|
|
|
311 |
|
312 |
-
# Process image
|
313 |
-
if uploaded_file is not None
|
314 |
-
# Handle
|
315 |
-
if
|
316 |
try:
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
image = Image.open(BytesIO(response.content)).convert('RGB')
|
321 |
-
except Exception as e:
|
322 |
-
st.error(f"Error loading example image: {e}")
|
323 |
return
|
324 |
-
else:
|
325 |
-
# User uploaded image
|
326 |
-
image = Image.open(uploaded_file).convert('RGB')
|
327 |
-
|
328 |
st.markdown("---")
|
329 |
|
330 |
analysis_container = st.container()
|
@@ -333,6 +328,7 @@ def main():
|
|
333 |
|
334 |
with col1:
|
335 |
st.markdown('<h3 class="sub-header">Uploaded Image</h3>', unsafe_allow_html=True)
|
|
|
336 |
st.image(image, caption="", use_container_width=True)
|
337 |
|
338 |
with col2:
|
|
|
59 |
|
60 |
# Define function to load model
|
61 |
@st.cache_resource
|
62 |
+
def load_model(model_path="model_comparison/best_model/model.pth"):
|
63 |
# Try to find model_info.json to determine which model architecture to use
|
64 |
model_dir = os.path.dirname(model_path)
|
65 |
model_info_path = os.path.join(model_dir, "model_info.json")
|
|
|
290 |
with upload_container:
|
291 |
uploaded_file = st.file_uploader("Choose a leaf image to analyze", type=["jpg", "jpeg", "png"])
|
292 |
|
293 |
+
# Add test images from test_images folder
|
294 |
+
st.markdown("<h3>Or select a test image:</h3>", unsafe_allow_html=True)
|
295 |
+
test_cols = st.columns(4)
|
296 |
|
297 |
+
# Get test images from test_images folder
|
298 |
+
test_images = []
|
299 |
+
for root, dirs, files in os.walk("test_images"):
|
300 |
+
for file in files:
|
301 |
+
if file.lower().endswith((".jpg", ".jpeg", ".png")):
|
302 |
+
test_images.append({"name": file, "path": os.path.join(root, file)})
|
|
|
303 |
|
304 |
+
# Display test images
|
305 |
+
use_test = None
|
306 |
+
for i, test_img in enumerate(test_images):
|
307 |
+
with test_cols[i % 4]:
|
308 |
+
folder_type = "Healthy" if "healthy" in test_img["path"].lower() else "Spider Mite Infested"
|
309 |
+
st.image(test_img["path"], caption=folder_type, width=150)
|
310 |
+
if st.button(f"Use {folder_type}", key=f"test_button_{i}"):
|
311 |
+
use_test = test_img["path"]
|
312 |
+
uploaded_file = use_test
|
313 |
|
314 |
+
# Process image if uploaded
|
315 |
+
if uploaded_file is not None:
|
316 |
+
# Handle test image path
|
317 |
+
if isinstance(uploaded_file, str):
|
318 |
try:
|
319 |
+
image = Image.open(uploaded_file).convert('RGB')
|
320 |
+
except:
|
321 |
+
st.error(f"Could not open test image: {uploaded_file}")
|
|
|
|
|
|
|
322 |
return
|
|
|
|
|
|
|
|
|
323 |
st.markdown("---")
|
324 |
|
325 |
analysis_container = st.container()
|
|
|
328 |
|
329 |
with col1:
|
330 |
st.markdown('<h3 class="sub-header">Uploaded Image</h3>', unsafe_allow_html=True)
|
331 |
+
image = Image.open(uploaded_file).convert('RGB')
|
332 |
st.image(image, caption="", use_container_width=True)
|
333 |
|
334 |
with col2:
|