Conversation
Reviewer's GuideAdds a Streamlit-based UI and a TensorFlow-backed classifier abstraction for an AI-powered waste classification demo, including model path resolution, caching, and image preprocessing aligned with a MobileNetV2 training pipeline. Sequence diagram for Streamlit image classification flowsequenceDiagram
actor User
participant StreamlitApp
participant WasteClassifier
participant TFKerasModel
User ->> StreamlitApp: st.file_uploader
StreamlitApp ->> StreamlitApp: load_cached_classifier
StreamlitApp ->> WasteClassifier: predict(image)
WasteClassifier ->> WasteClassifier: _preprocess_image(image)
WasteClassifier ->> TFKerasModel: predict(processed_img)
TFKerasModel -->> WasteClassifier: predictions
WasteClassifier -->> StreamlitApp: predicted_class, confidence
StreamlitApp ->> User: st.success / st.metric / st.info
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
resolve_model_path, returningMODEL_CANDIDATES[0]when no candidate exists can silently pass a non-existent path down toWasteClassifier; consider raising a clear exception or surfacing a user-facing error instead of defaulting to a missing file. - There is a slight inconsistency between
resolve_model_path(which accepts any existing candidate, even if not a zip) andWasteClassifier.load_model(which requireszipfile.is_zipfile); aligning these checks will avoid confusingValueErrorfailures when a non-zip.kerasfile is selected by the resolver.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `resolve_model_path`, returning `MODEL_CANDIDATES[0]` when no candidate exists can silently pass a non-existent path down to `WasteClassifier`; consider raising a clear exception or surfacing a user-facing error instead of defaulting to a missing file.
- There is a slight inconsistency between `resolve_model_path` (which accepts any existing candidate, even if not a zip) and `WasteClassifier.load_model` (which requires `zipfile.is_zipfile`); aligning these checks will avoid confusing `ValueError` failures when a non-zip `.keras` file is selected by the resolver.
## Individual Comments
### Comment 1
<location path="classifier.py" line_range="53-54" />
<code_context>
+ model_file = Path(model_path)
+ if not model_file.is_file():
+ raise FileNotFoundError(f"Model dosyası bulunamadı: {model_file}")
+ if not zipfile.is_zipfile(model_file):
+ raise ValueError(f"Model dosyası geçersiz .keras arşivi: {model_file}")
+
+ try:
</code_context>
<issue_to_address>
**issue (bug_risk):** Model format doğrulaması `resolve_model_path` ile tutarsız görünüyor.
Burada `.keras` dosyasının mutlaka `zipfile.is_zipfile` olması şartı, `resolve_model_path` içindeki ikinci döngüyle çelişiyor; orada zip kontrolü yapılmadan da model yolu dönebiliyor. Böylece `resolve_model_path` bir dosyayı seçerken, `WasteClassifier` aynı dosyayı “format geçersiz” diyerek reddedebilir.
Bu tutarsızlığı gidermek için ya `resolve_model_path` yalnızca `zipfile.is_zipfile` olan adayları döndürmeli, ya da burada zip kontrolünü uyarı/log seviyesine çekip zip olmayan `.keras` dosyalarının da yüklenmesine izin vermelisiniz. Aksi halde geçerli bir model dosyası için kullanıcı gereksiz yere "dosya geçersiz" hatası alabilir.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if not zipfile.is_zipfile(model_file): | ||
| raise ValueError(f"Model dosyası geçersiz .keras arşivi: {model_file}") |
There was a problem hiding this comment.
issue (bug_risk): Model format doğrulaması resolve_model_path ile tutarsız görünüyor.
Burada .keras dosyasının mutlaka zipfile.is_zipfile olması şartı, resolve_model_path içindeki ikinci döngüyle çelişiyor; orada zip kontrolü yapılmadan da model yolu dönebiliyor. Böylece resolve_model_path bir dosyayı seçerken, WasteClassifier aynı dosyayı “format geçersiz” diyerek reddedebilir.
Bu tutarsızlığı gidermek için ya resolve_model_path yalnızca zipfile.is_zipfile olan adayları döndürmeli, ya da burada zip kontrolünü uyarı/log seviyesine çekip zip olmayan .keras dosyalarının da yüklenmesine izin vermelisiniz. Aksi halde geçerli bir model dosyası için kullanıcı gereksiz yere "dosya geçersiz" hatası alabilir.
There was a problem hiding this comment.
Pull request overview
Adds a Streamlit-based web UI for classifying uploaded waste images using the trained MobileNetV2/Keras model, with a reusable classifier abstraction for loading the model, preprocessing images, and returning predictions.
Changes:
- Added
WasteClassifierandBaseClassifierfor TensorFlow model loading, preprocessing, and prediction. - Added
app.pyStreamlit interface with model path resolution, cached classifier loading, image upload, and prediction display. - Maps model output classes to Turkish waste category labels.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
classifier.py |
Adds reusable TensorFlow/PIL image classification logic for the waste model. |
app.py |
Adds the Streamlit UI, model discovery/caching, upload flow, and prediction result display. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @st.cache_resource | ||
| def load_cached_classifier(): |
|
|
||
| if uploaded_file is not None: | ||
| # Görseli RAM'e alıyoruz | ||
| image = Image.open(uploaded_file) |
| import streamlit as st | ||
| from PIL import Image | ||
| from classifier import WasteClassifier |
Summary by Sourcery
Add a Streamlit-based web application for waste image classification using a TensorFlow MobileNetV2 model.
New Features:
Enhancements: