Sync from GitHub 549e940
Browse files- models/minicpm.py +17 -8
models/minicpm.py
CHANGED
|
@@ -97,13 +97,16 @@ CLASSIFY_PROMPT = (
|
|
| 97 |
# <box>x1 y1 x2 y2</box> form with coordinates normalized to 0-1000.
|
| 98 |
GROUND_PROMPT = (
|
| 99 |
"The image is one page of a repair manual. A mechanic asked to circle "
|
| 100 |
-
"{query!r} on this page.
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
-
"
|
| 106 |
-
"
|
|
|
|
|
|
|
|
|
|
| 107 |
)
|
| 108 |
|
| 109 |
FIGURE_PROMPT = (
|
|
@@ -285,7 +288,13 @@ def ground_box(
|
|
| 285 |
max_new_tokens=64,
|
| 286 |
)
|
| 287 |
raw = str(out).strip()
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
if len(nums) < 4:
|
| 290 |
return None, raw
|
| 291 |
x1, y1, x2, y2 = (min(1000.0, max(0.0, float(n))) for n in nums[:4])
|
|
|
|
| 97 |
# <box>x1 y1 x2 y2</box> form with coordinates normalized to 0-1000.
|
| 98 |
GROUND_PROMPT = (
|
| 99 |
"The image is one page of a repair manual. A mechanic asked to circle "
|
| 100 |
+
"{query!r} on this page. Locate it precisely:\n"
|
| 101 |
+
"- In an exploded or assembly diagram, parts carry callout numbers/letters "
|
| 102 |
+
"on leader lines, and a legend lists what each number is. Find {query!r} in "
|
| 103 |
+
"the legend to get its number, then follow that number's leader line to the "
|
| 104 |
+
"part in the drawing and box THAT part (not the legend text).\n"
|
| 105 |
+
"- Otherwise it may be a row in a table, a specification value, or a "
|
| 106 |
+
"heading — box that.\n"
|
| 107 |
+
"Reply with ONLY the box, as <box>x1 y1 x2 y2</box>: four integers "
|
| 108 |
+
"normalized to 0-1000 (x left→right, y top→bottom) over the whole page, "
|
| 109 |
+
"and nothing else. If it is not on this page, reply exactly: NOT FOUND"
|
| 110 |
)
|
| 111 |
|
| 112 |
FIGURE_PROMPT = (
|
|
|
|
| 288 |
max_new_tokens=64,
|
| 289 |
)
|
| 290 |
raw = str(out).strip()
|
| 291 |
+
if "NOT FOUND" in raw.upper():
|
| 292 |
+
return None, raw
|
| 293 |
+
# Read the coordinates from the <box>…</box> tag specifically. MiniCPM-V
|
| 294 |
+
# may prefix a <ref>…</ref> (e.g. echoing "5. Rod"); that digit would
|
| 295 |
+
# otherwise be grabbed as the first coordinate and shift the whole box.
|
| 296 |
+
m = re.search(r"<box>(.*?)</box>", raw, re.IGNORECASE | re.DOTALL)
|
| 297 |
+
nums = re.findall(r"\d+(?:\.\d+)?", m.group(1) if m else raw)
|
| 298 |
if len(nums) < 4:
|
| 299 |
return None, raw
|
| 300 |
x1, y1, x2, y2 = (min(1000.0, max(0.0, float(n))) for n in nums[:4])
|