Apiarist Dev commited on
Commit ·
19fed7f
1
Parent(s): 3f394fc
fix: run YOLO on main container, not GPU worker (file access + log visibility)
Browse files
app.py
CHANGED
|
@@ -231,47 +231,17 @@ def analyze_frame(image: Image.Image, hive_name: str):
|
|
| 231 |
|
| 232 |
|
| 233 |
def _run_qwen(image: Image.Image, prefix: str = "") -> str:
|
| 234 |
-
"""
|
| 235 |
-
|
| 236 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 237 |
-
dtype = torch.float16 if device == "cuda" else torch.float32
|
| 238 |
-
model = model.to(device=device, dtype=dtype)
|
| 239 |
-
|
| 240 |
-
messages = [
|
| 241 |
-
{
|
| 242 |
-
"role": "user",
|
| 243 |
-
"content": [
|
| 244 |
-
{"type": "image", "image": image},
|
| 245 |
-
{"type": "text", "text": prefix + INSPECTION_PROMPT},
|
| 246 |
-
],
|
| 247 |
-
}
|
| 248 |
-
]
|
| 249 |
-
inputs = processor.apply_chat_template(
|
| 250 |
-
messages,
|
| 251 |
-
tokenize=True,
|
| 252 |
-
add_generation_prompt=True,
|
| 253 |
-
return_dict=True,
|
| 254 |
-
return_tensors="pt",
|
| 255 |
-
).to(device)
|
| 256 |
-
|
| 257 |
-
with torch.no_grad():
|
| 258 |
-
generated = model.generate(
|
| 259 |
-
**inputs, max_new_tokens=300, do_sample=False
|
| 260 |
-
)
|
| 261 |
-
prompt_len = inputs["input_ids"].shape[1]
|
| 262 |
-
return processor.batch_decode(
|
| 263 |
-
generated[:, prompt_len:], skip_special_tokens=True
|
| 264 |
-
)[0].strip()
|
| 265 |
|
| 266 |
|
| 267 |
-
@gpu
|
| 268 |
def run_comparison(image: Image.Image):
|
| 269 |
"""A/B: Apiarist (YOLO + Qwen) vs raw Qwen alone, side-by-side."""
|
| 270 |
if image is None:
|
| 271 |
msg = "Upload a frame photo to compare."
|
| 272 |
return None, msg, None, msg
|
| 273 |
|
| 274 |
-
#
|
| 275 |
detections, annotated = detector.detect(image)
|
| 276 |
counts = detector.summarize_counts(detections)
|
| 277 |
yolo_active = detector.is_available()
|
|
|
|
| 231 |
|
| 232 |
|
| 233 |
def _run_qwen(image: Image.Image, prefix: str = "") -> str:
|
| 234 |
+
"""Convenience wrapper that calls the GPU-only Qwen function."""
|
| 235 |
+
return _qwen_only(image, prefix + INSPECTION_PROMPT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
|
|
|
|
| 238 |
def run_comparison(image: Image.Image):
|
| 239 |
"""A/B: Apiarist (YOLO + Qwen) vs raw Qwen alone, side-by-side."""
|
| 240 |
if image is None:
|
| 241 |
msg = "Upload a frame photo to compare."
|
| 242 |
return None, msg, None, msg
|
| 243 |
|
| 244 |
+
# YOLO on main container (CPU, fast)
|
| 245 |
detections, annotated = detector.detect(image)
|
| 246 |
counts = detector.summarize_counts(detections)
|
| 247 |
yolo_active = detector.is_available()
|