-
Notifications
You must be signed in to change notification settings - Fork 36
Add Western-style detectors (Graffiti, Traffic Sign, Abandoned Vehicle) to UI #472
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
98a3978
fbe8d49
fcd102d
9b8b2ef
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 |
|---|---|---|
|
|
@@ -5,11 +5,12 @@ | |
| from typing import Union, List, Dict, Any | ||
| from PIL import Image | ||
| import logging | ||
| from backend.config import get_hf_token | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # HF_TOKEN should be set in environment variables | ||
| token = os.environ.get("HF_TOKEN") | ||
| token = get_hf_token() | ||
| headers = {"Authorization": f"Bearer {token}"} if token else {} | ||
|
Comment on lines
+13
to
14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compute auth headers at request time, not module import time. Capturing Suggested fix-token = get_hf_token()
-headers = {"Authorization": f"Bearer {token}"} if token else {}
+def _auth_headers() -> Dict[str, str]:
+ token = get_hf_token()
+ return {"Authorization": f"Bearer {token}"} if token else {}
@@
- response = await client.post(url, headers=headers, json=payload, timeout=20.0)
+ response = await client.post(url, headers=_auth_headers(), json=payload, timeout=20.0)Apply the same 🤖 Prompt for AI Agents |
||
|
|
||
| # Zero-Shot Image Classification Model | ||
|
|
@@ -456,3 +457,27 @@ async def detect_abandoned_vehicle_clip(image: Union[Image.Image, bytes], client | |
| labels = ["abandoned car", "rusted vehicle", "car with flat tires", "wrecked car", "normal parked car"] | ||
| targets = ["abandoned car", "rusted vehicle", "car with flat tires", "wrecked car"] | ||
| return await _detect_clip_generic(image, labels, targets, client) | ||
|
|
||
| async def detect_vandalism_clip(image: Union[Image.Image, bytes], client: httpx.AsyncClient = None): | ||
| """ | ||
| Detects vandalism/graffiti. | ||
| """ | ||
| labels = ["graffiti", "vandalism", "spray paint", "street art", "clean wall", "public property", "normal street"] | ||
| targets = ["graffiti", "vandalism", "spray paint"] | ||
| return await _detect_clip_generic(image, labels, targets, client) | ||
|
|
||
| async def detect_infrastructure_clip(image: Union[Image.Image, bytes], client: httpx.AsyncClient = None): | ||
| """ | ||
| Detects general infrastructure damage. | ||
| """ | ||
| labels = ["broken streetlight", "damaged traffic sign", "fallen tree", "damaged fence", "pothole", "clean street", "normal infrastructure"] | ||
| targets = ["broken streetlight", "damaged traffic sign", "fallen tree", "damaged fence"] | ||
| return await _detect_clip_generic(image, labels, targets, client) | ||
|
|
||
| async def detect_flooding_clip(image: Union[Image.Image, bytes], client: httpx.AsyncClient = None): | ||
| """ | ||
| Detects flooding/waterlogging (outdoor). | ||
| """ | ||
| labels = ["flooded street", "waterlogging", "blocked drain", "heavy rain", "dry street", "normal road"] | ||
| targets = ["flooded street", "waterlogging", "blocked drain", "heavy rain"] | ||
| return await _detect_clip_generic(image, labels, targets, client) | ||
|
Comment on lines
+461
to
+483
|
||
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.
Avoid forcing full app config load when only HF token is needed.
get_hf_token()callsget_config(), which can exit the process if unrelated required keys are missing. That makes HF-only code paths brittle.Suggested fix
def get_hf_token() -> Optional[str]: """Get Hugging Face token from config.""" - return get_config().hf_token + global _config + if _config is not None: + return _config.hf_token + # Allow HF token lookup without forcing full Config bootstrap + return os.getenv("HF_TOKEN")🤖 Prompt for AI Agents