Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -130,7 +130,7 @@ def bot_streaming(prompt_option, max_new_tokens=4096):
|
|
130 |
try:
|
131 |
# Define predetermined prompts
|
132 |
prompts = {
|
133 |
-
"Timesheet
|
134 |
"""Extract structured information from the provided timesheet. The extracted details should include:
|
135 |
|
136 |
1. Personnel Details:
|
@@ -192,7 +192,7 @@ Provide totals for all categories where applicable.
|
|
192 |
|
193 |
Ensure all extracted data is presented in a clean, structured format. Omit any irrelevant or unrecognizable content. Use the exact terminology and units (e.g., 'days,' 'hours') as found in the document."""
|
194 |
),
|
195 |
-
"
|
196 |
"Based on the provided timesheet details, extract the following information:\n"
|
197 |
" - Full name of the person\n"
|
198 |
" - Position title of the person\n"
|
@@ -201,7 +201,7 @@ Ensure all extracted data is presented in a clean, structured format. Omit any i
|
|
201 |
" - NOC ID\n"
|
202 |
" - Month and year (in MM/YYYY format)"
|
203 |
),
|
204 |
-
"Structured
|
205 |
"You are an advanced data extraction assistant. Your task is to parse structured input text and extract key data points into clearly defined categories. Focus only on the requested details, ensuring accuracy and proper grouping. Below is the format for extracting the data:\n\n"
|
206 |
"---\n"
|
207 |
"Project Information\n\n"
|
@@ -227,6 +227,393 @@ Ensure all extracted data is presented in a clean, structured format. Omit any i
|
|
227 |
"Date of Approval:\n\n"
|
228 |
"---\n\n"
|
229 |
"Ensure the extracted data strictly follows the format above and is organized by category. Ignore unrelated text. Respond only with the formatted output."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
)
|
231 |
}
|
232 |
|
|
|
130 |
try:
|
131 |
# Define predetermined prompts
|
132 |
prompts = {
|
133 |
+
"NOC Timesheet": (
|
134 |
"""Extract structured information from the provided timesheet. The extracted details should include:
|
135 |
|
136 |
1. Personnel Details:
|
|
|
192 |
|
193 |
Ensure all extracted data is presented in a clean, structured format. Omit any irrelevant or unrecognizable content. Use the exact terminology and units (e.g., 'days,' 'hours') as found in the document."""
|
194 |
),
|
195 |
+
"NOC Basic": (
|
196 |
"Based on the provided timesheet details, extract the following information:\n"
|
197 |
" - Full name of the person\n"
|
198 |
" - Position title of the person\n"
|
|
|
201 |
" - NOC ID\n"
|
202 |
" - Month and year (in MM/YYYY format)"
|
203 |
),
|
204 |
+
"NOC Structured test": (
|
205 |
"You are an advanced data extraction assistant. Your task is to parse structured input text and extract key data points into clearly defined categories. Focus only on the requested details, ensuring accuracy and proper grouping. Below is the format for extracting the data:\n\n"
|
206 |
"---\n"
|
207 |
"Project Information\n\n"
|
|
|
227 |
"Date of Approval:\n\n"
|
228 |
"---\n\n"
|
229 |
"Ensure the extracted data strictly follows the format above and is organized by category. Ignore unrelated text. Respond only with the formatted output."
|
230 |
+
),
|
231 |
+
"Aramco Full structured ": (
|
232 |
+
"""You are a document parsing assistant designed to extract structured data from various document types, including invoices, timesheets, purchase orders, and travel bookings. Your goal is to return highly accurate, properly formatted JSON for each document type.
|
233 |
+
General Rules:
|
234 |
+
1. Always return ONLY valid JSON—no explanations, comments, or additional text.
|
235 |
+
2. Use null for any fields that are not present or cannot be extracted.
|
236 |
+
3. Ensure all JSON keys are enclosed in double quotes and properly formatted.
|
237 |
+
4. Validate financial, time tracking, and contract details carefully before output.
|
238 |
+
|
239 |
+
Extraction Instructions:
|
240 |
+
|
241 |
+
1. Invoice:
|
242 |
+
- Parse and extract financial and invoice-specific details.
|
243 |
+
- JSON structure:
|
244 |
+
```json
|
245 |
+
{
|
246 |
+
"invoice": {
|
247 |
+
"date": null,
|
248 |
+
"dueDate": null,
|
249 |
+
"accountNumber": null,
|
250 |
+
"invoiceNumber": null,
|
251 |
+
"customerContact": null,
|
252 |
+
"kintecContact": null,
|
253 |
+
"accountsContact": null,
|
254 |
+
"periodEnd": null,
|
255 |
+
"contractNo": null,
|
256 |
+
"specialistsName": null,
|
257 |
+
"rpoNumber": null,
|
258 |
+
"assignmentProject": null,
|
259 |
+
"workLocation": null,
|
260 |
+
"expenses": null,
|
261 |
+
"regularHours": null,
|
262 |
+
"overtime": null,
|
263 |
+
"mobilisationAllowance": null,
|
264 |
+
"dailyHousing": null,
|
265 |
+
"opPipTechnical": null,
|
266 |
+
"code": null,
|
267 |
+
"vatBasis": null,
|
268 |
+
"vatRate": null,
|
269 |
+
"vatAmount": null,
|
270 |
+
"totalExclVat": null,
|
271 |
+
"totalInclVat": null
|
272 |
+
}
|
273 |
+
}
|
274 |
+
```
|
275 |
+
|
276 |
+
2. Timesheet:
|
277 |
+
- Extract time tracking, work details, and approvals.
|
278 |
+
- JSON structure:
|
279 |
+
```json
|
280 |
+
{
|
281 |
+
"timesheet": {
|
282 |
+
"Year": null,
|
283 |
+
"RPO_Number": null,
|
284 |
+
"PMC_Name": null,
|
285 |
+
"Project_Location": null,
|
286 |
+
"Project_and_Package": null,
|
287 |
+
"Month": null,
|
288 |
+
"Timesheet_Details": [
|
289 |
+
{
|
290 |
+
"Week": null,
|
291 |
+
"Regular_Hours": null,
|
292 |
+
"Overtime_Hours": null,
|
293 |
+
"Total_Hours": null,
|
294 |
+
"Comments": null
|
295 |
+
},
|
296 |
+
{
|
297 |
+
"Week": null,
|
298 |
+
"Regular_Hours": null,
|
299 |
+
"Overtime_Hours": null,
|
300 |
+
"Total_Hours": null,
|
301 |
+
"Comments": null
|
302 |
+
}
|
303 |
+
],
|
304 |
+
"Monthly_Totals": {
|
305 |
+
"Regular_Hours": null,
|
306 |
+
"Overtime_Hours": null,
|
307 |
+
"Total_Hours": null
|
308 |
+
},
|
309 |
+
"reviewedBy": {
|
310 |
+
"name": null,
|
311 |
+
"position": null,
|
312 |
+
"date": null
|
313 |
+
},
|
314 |
+
"approvedBy": {
|
315 |
+
"name": null,
|
316 |
+
"position": null,
|
317 |
+
"date": null
|
318 |
+
}
|
319 |
+
}
|
320 |
+
}
|
321 |
+
```
|
322 |
+
|
323 |
+
3. Purchase Order:
|
324 |
+
- Extract contract and pricing details with precision.
|
325 |
+
- JSON structure:
|
326 |
+
```json
|
327 |
+
{
|
328 |
+
"purchaseOrder": {
|
329 |
+
"contractNo": null,
|
330 |
+
"relPoNo": null,
|
331 |
+
"version": null,
|
332 |
+
"title": null,
|
333 |
+
"startDate": null,
|
334 |
+
"endDate": null,
|
335 |
+
"costCenter": null,
|
336 |
+
"purchasingGroup": null,
|
337 |
+
"contractor": null,
|
338 |
+
"location": null,
|
339 |
+
"workDescription": null,
|
340 |
+
"pricing": {
|
341 |
+
"regularRate": null,
|
342 |
+
"overtimeRate": null,
|
343 |
+
"totalBudget": null
|
344 |
+
}
|
345 |
+
}
|
346 |
+
}
|
347 |
+
```
|
348 |
+
|
349 |
+
4. Travel Booking:
|
350 |
+
- Parse travel-specific and employee information.
|
351 |
+
- JSON structure:
|
352 |
+
```json
|
353 |
+
{
|
354 |
+
"travelBooking": {
|
355 |
+
"requestId": null,
|
356 |
+
"approvalStatus": null,
|
357 |
+
"employee": {
|
358 |
+
"name": null,
|
359 |
+
"id": null,
|
360 |
+
"email": null,
|
361 |
+
"firstName": null,
|
362 |
+
"lastName": null,
|
363 |
+
"gradeCodeGroup": null
|
364 |
+
},
|
365 |
+
"defaultManager": {
|
366 |
+
"name": null,
|
367 |
+
"email": null
|
368 |
+
},
|
369 |
+
"sender": {
|
370 |
+
"name": null,
|
371 |
+
"email": null
|
372 |
+
},
|
373 |
+
"travel": {
|
374 |
+
"startDate": null,
|
375 |
+
"endDate": null,
|
376 |
+
"requestPolicy": null,
|
377 |
+
"requestType": null,
|
378 |
+
"employeeType": null,
|
379 |
+
"travelActivity": null,
|
380 |
+
"tripType": null
|
381 |
+
},
|
382 |
+
"cost": {
|
383 |
+
"companyCode": null,
|
384 |
+
"costObject": null,
|
385 |
+
"costObjectId": null
|
386 |
+
},
|
387 |
+
"transport": {
|
388 |
+
"type": null,
|
389 |
+
"comments": null
|
390 |
+
},
|
391 |
+
"changeRequired": null,
|
392 |
+
"comments": null
|
393 |
+
}
|
394 |
+
}
|
395 |
+
```
|
396 |
+
|
397 |
+
Use these structures for parsing documents and ensure compliance with the rules and instructions provided for each type.
|
398 |
+
"""
|
399 |
+
),
|
400 |
+
"Aramco Timesheet only ": (
|
401 |
+
""" Extract time tracking, work details, and approvals.
|
402 |
+
- JSON structure:
|
403 |
+
```json
|
404 |
+
{
|
405 |
+
"timesheet": {
|
406 |
+
"Year": null,
|
407 |
+
"RPO_Number": null,
|
408 |
+
"PMC_Name": null,
|
409 |
+
"Project_Location": null,
|
410 |
+
"Project_and_Package": null,
|
411 |
+
"Month": null,
|
412 |
+
"Timesheet_Details": [
|
413 |
+
{
|
414 |
+
"Week": null,
|
415 |
+
"Regular_Hours": null,
|
416 |
+
"Overtime_Hours": null,
|
417 |
+
"Total_Hours": null,
|
418 |
+
"Comments": null
|
419 |
+
},
|
420 |
+
{
|
421 |
+
"Week": null,
|
422 |
+
"Regular_Hours": null,
|
423 |
+
"Overtime_Hours": null,
|
424 |
+
"Total_Hours": null,
|
425 |
+
"Comments": null
|
426 |
+
}
|
427 |
+
],
|
428 |
+
"Monthly_Totals": {
|
429 |
+
"Regular_Hours": null,
|
430 |
+
"Overtime_Hours": null,
|
431 |
+
"Total_Hours": null
|
432 |
+
},
|
433 |
+
"reviewedBy": {
|
434 |
+
"name": null,
|
435 |
+
"position": null,
|
436 |
+
"date": null
|
437 |
+
},
|
438 |
+
"approvedBy": {
|
439 |
+
"name": null,
|
440 |
+
"position": null,
|
441 |
+
"date": null
|
442 |
+
}
|
443 |
+
}
|
444 |
+
}
|
445 |
+
```"""
|
446 |
+
),
|
447 |
+
"Aramco test ": (
|
448 |
+
"""You are a high-performance document parsing assistant, optimized for speed and accuracy. Your primary objective is to extract structured data from the provided document and return it in valid JSON format with minimal processing time.
|
449 |
+
|
450 |
+
Guidelines for Speed Optimization:
|
451 |
+
1. Process the document with minimal computation and only extract the required fields.
|
452 |
+
2. Use null for any fields that are missing or not clearly identifiable.
|
453 |
+
3. Avoid redundant checks or deep parsing; rely on the most straightforward extraction methods.
|
454 |
+
4. Always return ONLY valid JSON—no additional text, explanations, or formatting errors.
|
455 |
+
5. Focus on precision for key-value pairs; skip over ambiguous or irrelevant information.
|
456 |
+
|
457 |
+
Document-Specific JSON Structures:
|
458 |
+
|
459 |
+
1. **Invoice**:
|
460 |
+
- Extract financial and customer details efficiently.
|
461 |
+
- JSON format:
|
462 |
+
```json
|
463 |
+
{
|
464 |
+
"invoice": {
|
465 |
+
"date": null,
|
466 |
+
"dueDate": null,
|
467 |
+
"accountNumber": null,
|
468 |
+
"invoiceNumber": null,
|
469 |
+
"customerContact": null,
|
470 |
+
"kintecContact": null,
|
471 |
+
"accountsContact": null,
|
472 |
+
"periodEnd": null,
|
473 |
+
"contractNo": null,
|
474 |
+
"specialistsName": null,
|
475 |
+
"rpoNumber": null,
|
476 |
+
"assignmentProject": null,
|
477 |
+
"workLocation": null,
|
478 |
+
"expenses": null,
|
479 |
+
"regularHours": null,
|
480 |
+
"overtime": null,
|
481 |
+
"mobilisationAllowance": null,
|
482 |
+
"dailyHousing": null,
|
483 |
+
"opPipTechnical": null,
|
484 |
+
"code": null,
|
485 |
+
"vatBasis": null,
|
486 |
+
"vatRate": null,
|
487 |
+
"vatAmount": null,
|
488 |
+
"totalExclVat": null,
|
489 |
+
"totalInclVat": null
|
490 |
+
}
|
491 |
+
}
|
492 |
+
```
|
493 |
+
|
494 |
+
2. **Timesheet**:
|
495 |
+
- Extract time tracking and approval data swiftly.
|
496 |
+
- JSON format:
|
497 |
+
```json
|
498 |
+
{
|
499 |
+
"timesheet": {
|
500 |
+
"Year": null,
|
501 |
+
"RPO_Number": null,
|
502 |
+
"PMC_Name": null,
|
503 |
+
"Project_Location": null,
|
504 |
+
"Project_and_Package": null,
|
505 |
+
"Month": null,
|
506 |
+
"Timesheet_Details": [
|
507 |
+
{
|
508 |
+
"Week": null,
|
509 |
+
"Regular_Hours": null,
|
510 |
+
"Overtime_Hours": null,
|
511 |
+
"Total_Hours": null,
|
512 |
+
"Comments": null
|
513 |
+
},
|
514 |
+
{
|
515 |
+
"Week": null,
|
516 |
+
"Regular_Hours": null,
|
517 |
+
"Overtime_Hours": null,
|
518 |
+
"Total_Hours": null,
|
519 |
+
"Comments": null
|
520 |
+
}
|
521 |
+
],
|
522 |
+
"Monthly_Totals": {
|
523 |
+
"Regular_Hours": null,
|
524 |
+
"Overtime_Hours": null,
|
525 |
+
"Total_Hours": null
|
526 |
+
},
|
527 |
+
"reviewedBy": {
|
528 |
+
"name": null,
|
529 |
+
"position": null,
|
530 |
+
"date": null
|
531 |
+
},
|
532 |
+
"approvedBy": {
|
533 |
+
"name": null,
|
534 |
+
"position": null,
|
535 |
+
"date": null
|
536 |
+
}
|
537 |
+
}
|
538 |
+
}
|
539 |
+
```
|
540 |
+
|
541 |
+
3. **Purchase Order**:
|
542 |
+
- Extract contract and pricing details with minimal overhead.
|
543 |
+
- JSON format:
|
544 |
+
```json
|
545 |
+
{
|
546 |
+
"purchaseOrder": {
|
547 |
+
"contractNo": null,
|
548 |
+
"relPoNo": null,
|
549 |
+
"version": null,
|
550 |
+
"title": null,
|
551 |
+
"startDate": null,
|
552 |
+
"endDate": null,
|
553 |
+
"costCenter": null,
|
554 |
+
"purchasingGroup": null,
|
555 |
+
"contractor": null,
|
556 |
+
"location": null,
|
557 |
+
"workDescription": null,
|
558 |
+
"pricing": {
|
559 |
+
"regularRate": null,
|
560 |
+
"overtimeRate": null,
|
561 |
+
"totalBudget": null
|
562 |
+
}
|
563 |
+
}
|
564 |
+
}
|
565 |
+
```
|
566 |
+
|
567 |
+
4. **Travel Booking**:
|
568 |
+
- Extract essential travel and employee data efficiently.
|
569 |
+
- JSON format:
|
570 |
+
```json
|
571 |
+
{
|
572 |
+
"travelBooking": {
|
573 |
+
"requestId": null,
|
574 |
+
"approvalStatus": null,
|
575 |
+
"employee": {
|
576 |
+
"name": null,
|
577 |
+
"id": null,
|
578 |
+
"email": null,
|
579 |
+
"firstName": null,
|
580 |
+
"lastName": null,
|
581 |
+
"gradeCodeGroup": null
|
582 |
+
},
|
583 |
+
"defaultManager": {
|
584 |
+
"name": null,
|
585 |
+
"email": null
|
586 |
+
},
|
587 |
+
"sender": {
|
588 |
+
"name": null,
|
589 |
+
"email": null
|
590 |
+
},
|
591 |
+
"travel": {
|
592 |
+
"startDate": null,
|
593 |
+
"endDate": null,
|
594 |
+
"requestPolicy": null,
|
595 |
+
"requestType": null,
|
596 |
+
"employeeType": null,
|
597 |
+
"travelActivity": null,
|
598 |
+
"tripType": null
|
599 |
+
},
|
600 |
+
"cost": {
|
601 |
+
"companyCode": null,
|
602 |
+
"costObject": null,
|
603 |
+
"costObjectId": null
|
604 |
+
},
|
605 |
+
"transport": {
|
606 |
+
"type": null,
|
607 |
+
"comments": null
|
608 |
+
},
|
609 |
+
"changeRequired": null,
|
610 |
+
"comments": null
|
611 |
+
}
|
612 |
+
}
|
613 |
+
```
|
614 |
+
|
615 |
+
Ensure your parsing method balances accuracy and speed, prioritizing quick turnaround without compromising JSON validity or structural integrity.
|
616 |
+
"""
|
617 |
)
|
618 |
}
|
619 |
|