Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,35 +8,38 @@ from google.genai import types
|
|
8 |
from pdf2image import convert_from_bytes
|
9 |
|
10 |
DETECTION_PROMPT = """\
|
11 |
-
Analyze this document image and identify
|
12 |
-
|
13 |
-
|
14 |
-
-
|
15 |
-
-
|
16 |
-
-
|
17 |
-
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
-
|
28 |
-
-
|
29 |
-
-
|
30 |
-
|
31 |
-
|
32 |
-
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
"""
|
41 |
|
42 |
TEXT_EXTRACTION_PROMPT = "Extract the text in this image. Return only the exact text, nothing else."
|
|
|
8 |
from pdf2image import convert_from_bytes
|
9 |
|
10 |
DETECTION_PROMPT = """\
|
11 |
+
Analyze this document image and identify text regions following these rules:
|
12 |
+
|
13 |
+
1. GROUP RELATED CONTENT:
|
14 |
+
- Full tables as SINGLE regions (including headers and all rows)
|
15 |
+
- Paragraphs as SINGLE rectangular blocks (multiple lines as one box)
|
16 |
+
- Keep text columns intact
|
17 |
+
- Treat list items as single region if visually grouped
|
18 |
+
|
19 |
+
2. TEXT REGION REQUIREMENTS:
|
20 |
+
- Boundaries must tightly wrap text content
|
21 |
+
- Include 2% padding around text clusters
|
22 |
+
- Exclude isolated decorative elements
|
23 |
+
- Merge adjacent text fragments with ≤1% spacing
|
24 |
+
|
25 |
+
3. COORDINATE FORMAT:
|
26 |
+
Python list of lists [[xmin, ymin, xmax, ymax]]
|
27 |
+
- Normalized 0-1 with 3 decimal places
|
28 |
+
- Ordered top-to-bottom, left-to-right
|
29 |
+
- Table example: [[0.12, 0.35, 0.88, 0.65]] for full table
|
30 |
+
|
31 |
+
4. SPECIAL CASES:
|
32 |
+
- Table cells should NOT have individual boxes
|
33 |
+
- Page headers/footers as separate regions
|
34 |
+
- Text wrapped around images as distinct regions
|
35 |
+
|
36 |
+
Example response for table + 2 paragraphs:
|
37 |
+
[[0.07, 0.12, 0.93, 0.28], # Header
|
38 |
+
[0.12, 0.35, 0.88, 0.65], # Full table
|
39 |
+
[0.10, 0.70, 0.90, 0.85], # First paragraph
|
40 |
+
[0.10, 0.88, 0.90, 0.95]] # Second paragraph
|
41 |
+
|
42 |
+
ONLY RETURN THE PYTHON LIST! No explanations.
|
43 |
"""
|
44 |
|
45 |
TEXT_EXTRACTION_PROMPT = "Extract the text in this image. Return only the exact text, nothing else."
|