-
Notifications
You must be signed in to change notification settings - Fork 35
Add Waste Sorter, Optimize for Render/Netlify, & Restore Pothole Detection via HF #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4bf2677
1018e57
1e287a2
ddd8796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,8 +14,15 @@ | |||||||||||||||
| _model_loading_error: Optional[Exception] = None | ||||||||||||||||
| _model_initialized: bool = False | ||||||||||||||||
|
|
||||||||||||||||
| _model = None | ||||||||||||||||
| _model_lock = threading.Lock() | ||||||||||||||||
| def is_model_available(): | ||||||||||||||||
| """ | ||||||||||||||||
| Checks if the model dependencies are available. | ||||||||||||||||
| """ | ||||||||||||||||
| try: | ||||||||||||||||
| import ultralyticsplus | ||||||||||||||||
| return True | ||||||||||||||||
| except ImportError: | ||||||||||||||||
| return False | ||||||||||||||||
|
|
||||||||||||||||
| def load_model(): | ||||||||||||||||
| """ | ||||||||||||||||
|
|
@@ -44,9 +51,12 @@ def load_model(): | |||||||||||||||
|
|
||||||||||||||||
| logger.info("Model loaded successfully.") | ||||||||||||||||
| return model | ||||||||||||||||
| except ImportError: | ||||||||||||||||
| logger.warning("ultralyticsplus not installed. Pothole detection disabled.") | ||||||||||||||||
| return None | ||||||||||||||||
| except Exception as e: | ||||||||||||||||
| logger.error(f"Failed to load model: {e}") | ||||||||||||||||
| raise ModelLoadException("keremberke/yolov8n-pothole-segmentation", details={"error": str(e)}) from e | ||||||||||||||||
| return None | ||||||||||||||||
|
||||||||||||||||
| return None | |
| raise |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning an empty list when model is None makes a model-load/config problem indistinguishable from a real “no detections” result. If the API is expected to fall back to HF when the local model can’t run, consider raising a dedicated exception here (or in get_model()) so callers can reliably detect and handle the failure mode.
| return [] | |
| logger.error("Pothole detection model is not available (get_model() returned None).") | |
| raise DetectionException( | |
| "Pothole detection model is not available", | |
| "pothole", | |
| details={"error": "model_unavailable"} | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value masks “model unavailable” vs “no detections.”
An empty list is also a valid “no potholes” result, so callers can’t distinguish a load failure. Consider raising ModelLoadException (or another sentinel) so the caller can fall back or surface a 503.
🐛 Suggested change to surface model-unavailable explicitly
- if model is None:
- return []
+ if model is None:
+ raise ModelLoadException(
+ "keremberke/yolov8n-pothole-segmentation",
+ details={"error": "model unavailable"}
+ )
@@
- except Exception as e:
+ except ModelLoadException:
+ raise
+ except Exception as e:🤖 Prompt for AI Agents
In `@backend/pothole_detection.py` around lines 160 - 162, The current early
return "if model is None: return []" in backend/pothole_detection.py conflates
"model unavailable" with "no detections"; replace that empty-list return with
raising a specific sentinel exception (e.g., ModelLoadException) so callers can
distinguish failures from valid empty results, and add/declare the
ModelLoadException class (or reuse an existing error type) and update the
function docstring/signature where this check occurs to document the raised
exception so callers can catch it and respond (e.g., return 503).
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /* | ||
| X-Frame-Options: DENY | ||
| X-Content-Type-Options: nosniff | ||
| X-XSS-Protection: 1; mode=block | ||
| Referrer-Policy: strict-origin-when-cross-origin |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /* /index.html 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detect_pothole_endpointdecides between local vs HF usingis_model_available(), but that only checks whetherultralyticspluscan be imported. If the import succeeds butload_model()returnsNone(e.g., model download fails or other runtime error), this endpoint will still choose the local path and return empty detections instead of falling back to HF. Consider basing the decision on whether the model actually loaded (e.g., callget_model()once at startup / cache a readiness flag) or catch a local-model failure and then invokedetect_pothole_clipas fallback.