Seth0330 commited on
Commit
7154f00
·
verified ·
1 Parent(s): da57193

Update frontend/src/components/ocr/ExtractionOutput.jsx

Browse files
frontend/src/components/ocr/ExtractionOutput.jsx CHANGED
@@ -149,8 +149,58 @@ function fieldsToText(fields) {
149
  return "No data extracted.";
150
  }
151
 
152
- let text = "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
 
 
154
  const formatValue = (key, value, indent = "") => {
155
  if (Array.isArray(value)) {
156
  text += `${indent}${key}:\n`;
 
149
  return "No data extracted.";
150
  }
151
 
152
+ // If full_text exists, show it prominently first
153
+ if (fields.full_text) {
154
+ let text = "=== FULL EXTRACTED TEXT ===\n\n";
155
+ text += fields.full_text;
156
+
157
+ // If pages array exists, show per-page text
158
+ if (fields.pages && Array.isArray(fields.pages)) {
159
+ text += "\n\n=== TEXT BY PAGE ===\n\n";
160
+ fields.pages.forEach((page, idx) => {
161
+ text += `--- Page ${page.page_number || idx + 1} ---\n`;
162
+ text += page.text || "";
163
+ text += "\n\n";
164
+ });
165
+ }
166
+
167
+ // Then show other structured fields
168
+ const otherFields = { ...fields };
169
+ delete otherFields.full_text;
170
+ delete otherFields.pages;
171
+
172
+ if (Object.keys(otherFields).length > 0) {
173
+ text += "\n\n=== STRUCTURED FIELDS ===\n\n";
174
+ const formatValue = (key, value, indent = "") => {
175
+ if (Array.isArray(value)) {
176
+ text += `${indent}${key}:\n`;
177
+ value.forEach((item, idx) => {
178
+ if (typeof item === "object") {
179
+ text += `${indent} Item ${idx + 1}:\n`;
180
+ Object.entries(item).forEach(([k, v]) => formatValue(k, v, indent + " "));
181
+ } else {
182
+ text += `${indent} - ${item}\n`;
183
+ }
184
+ });
185
+ } else if (typeof value === "object" && value !== null) {
186
+ text += `${indent}${key}:\n`;
187
+ Object.entries(value).forEach(([k, v]) => formatValue(k, v, indent + " "));
188
+ } else {
189
+ text += `${indent}${key}: ${value}\n`;
190
+ }
191
+ };
192
+
193
+ Object.entries(otherFields).forEach(([key, value]) => {
194
+ formatValue(key, value);
195
+ text += "\n";
196
+ });
197
+ }
198
+
199
+ return text.trim();
200
+ }
201
 
202
+ // Fallback: format all fields normally
203
+ let text = "";
204
  const formatValue = (key, value, indent = "") => {
205
  if (Array.isArray(value)) {
206
  text += `${indent}${key}:\n`;