vithacocf commited on
Commit
b902076
·
verified ·
1 Parent(s): 5d887ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -10
app.py CHANGED
@@ -18,29 +18,82 @@ INTERNAL_MODEL_MAP = {
18
  "Gemini 2.5 Pro": "gemini-2.5-pro",
19
  }
20
  EXTERNAL_MODEL_NAME = "prithivMLmods/Camel-Doc-OCR-062825 (External)"
21
-
22
  PROMPT_FREIGHT_JSON = """
23
  Please analyze the freight rate table in the file I provide and convert it into JSON in the following structure:
24
  {
25
  "shipping_line": "...",
26
  "shipping_line_code": "...",
 
27
  "fee_type": "Air Freight",
28
  "valid_from": ...,
29
  "valid_to": ...,
30
- "charges": [...],
31
- "local_charges": [...]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
  ### Date rules
34
- - valid_from: DD/MM/YYYY, 01/MM/YYYY, 01/01/YYYY or 'UFN'
35
- - valid_to: DD/MM/YYYY or 'UFN'
 
 
 
 
 
 
36
  STRICT RULES:
37
- - Only return JSON, no explanation.
38
- - All rates must match the weight break columns (M,N,45kg,100kg,...).
39
- - Use IATA code for origin/destination.
40
- - Direction: Export if origin in Vietnam, else Import.
41
- - Combine with “notes” at bottom of PDF if relevant.
 
 
 
 
 
 
 
 
42
  """
43
 
 
44
  # ================== HELPERS ==================
45
  def _read_file_bytes(upload: Union[str, os.PathLike, dict, object] | None) -> bytes:
46
  if upload is None:
 
18
  "Gemini 2.5 Pro": "gemini-2.5-pro",
19
  }
20
  EXTERNAL_MODEL_NAME = "prithivMLmods/Camel-Doc-OCR-062825 (External)"
 
21
  PROMPT_FREIGHT_JSON = """
22
  Please analyze the freight rate table in the file I provide and convert it into JSON in the following structure:
23
  {
24
  "shipping_line": "...",
25
  "shipping_line_code": "...",
26
+ "shipping_line_reason": "Why this carrier is chosen?",
27
  "fee_type": "Air Freight",
28
  "valid_from": ...,
29
  "valid_to": ...,
30
+ "charges": [
31
+ {
32
+ "frequency": "...",
33
+ "package_type": "...",
34
+ "aircraft_type": "...",
35
+ "direction": "Export or Import or null",
36
+ "origin": "...",
37
+ "destination": "...",
38
+ "charge_name": "...",
39
+ "charge_code": "...",
40
+ "charge_code_reason": "...",
41
+ "cargo_type": "...",
42
+ "currency": "...",
43
+ "transit": "...",
44
+ "transit_time": "...",
45
+ "weight_breaks": {
46
+ "M": ...,
47
+ "N": ...,
48
+ "+45kg": ...,
49
+ "+100kg": ...,
50
+ "+300kg": ...,
51
+ "+500kg": ...,
52
+ "+1000kg": ...,
53
+ "other": {
54
+ key: value
55
+ },
56
+ "weight_breaks_reason":"Why chosen weight_breaks?"
57
+ },
58
+ "remark": "..."
59
+ }
60
+ ],
61
+ "local_charges": [
62
+ {
63
+ "charge_name": "...",
64
+ "charge_code": "...",
65
+ "unit": "...",
66
+ "amount": ...,
67
+ "remark": "..."
68
+ }
69
+ ]
70
  }
71
  ### Date rules
72
+ - valid_from format:
73
+ - `DD/MM/YYYY` (if full date)
74
+ - `01/MM/YYYY` (if month+year only)
75
+ - `01/01/YYYY` (if year only)
76
+ - `UFN` if missing
77
+ - valid_to:
78
+ - exact `DD/MM/YYYY` if present
79
+ - else `UFN`
80
  STRICT RULES:
81
+ - ONLY return a single JSON object as specified above.
82
+ - All rates must exactly match the corresponding weight break columns (M,N,45kg, 100kg, 300kg, 500kg, 1000kg, etc.). set null if N/A. No assumptions or interpolations.
83
+ - If the table shows "RQ" or similar, set value as "RQST".
84
+ - Group same-price destinations into one record separated by "/".
85
+ - Always use IATA code for origin and destination.
86
+ - Flight number (e.g. ZH118) is not charge code.
87
+ - Frequency: D[1-7]; 'Daily' = D1234567. Join multiple (e.g. D3,D4→D34).
88
+ - If local charges exist, list them.
89
+ - If validity missing, set null.
90
+ - Direction: Export if origin is Vietnam (SGN, HAN, DAD...), else Import.
91
+ - Provide short plain English reasons for "shipping_line_reason" & "charge_code_reason".
92
+ - Replace commas in remarks with semicolons.
93
+ - Only return JSON.
94
  """
95
 
96
+
97
  # ================== HELPERS ==================
98
  def _read_file_bytes(upload: Union[str, os.PathLike, dict, object] | None) -> bytes:
99
  if upload is None: