24 lines
701 B
Python
24 lines
701 B
Python
# -*- coding: utf-8 -*-
|
|
"""Response assembly utilities."""
|
|
from collections import Counter
|
|
|
|
|
|
def summarize_scene(objects):
|
|
if not objects:
|
|
return "no objects detected"
|
|
labels = [o.get('label', 'unknown') for o in objects]
|
|
counts = Counter(labels)
|
|
top = counts.most_common(3)
|
|
parts = ["{} x{}".format(lbl, cnt) for lbl, cnt in top]
|
|
return ', '.join(parts)
|
|
|
|
|
|
def build_response(text, blocks, objects, scene_summary, metadata, return_boxes=True):
|
|
resp = {
|
|
"text": text or "",
|
|
"blocks": blocks if return_boxes else [],
|
|
"objects": objects or [],
|
|
"scene_summary": scene_summary or "",
|
|
"meta": metadata or {},
|
|
}
|
|
return resp
|