ChintanSatva commited on
Commit
f12bf00
·
verified ·
1 Parent(s): 4affc50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -18,6 +18,7 @@ import cachetools
18
  import hashlib
19
  import google.generativeai as genai
20
  from dotenv import load_dotenv
 
21
 
22
  app = FastAPI()
23
 
@@ -34,7 +35,7 @@ if not api_key:
34
  logger.error("GOOGLE_API_KEY not set")
35
  raise HTTPException(status_code=500, detail="GOOGLE_API_KEY not set")
36
  genai.configure(api_key=api_key)
37
- model = genai.GenerativeModel("gemini-2.5-pro")
38
 
39
  # Set Tesseract path
40
  pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
@@ -116,11 +117,6 @@ async def process_with_gemini(filename: str, raw_text: str):
116
  - The 'items' list may have multiple entries, each with detailed attributes.
117
  - If a field is missing or not found, return an empty value (`""` or `0`) and set `accuracy` to `0.0`.
118
  - Convert any date found in format : YYYY-MM-DD
119
- - For Unit Price Format all numbers in standard decimal notation without exponents:
120
- - Correct: 0.0000009, 1500000, 0.00123
121
- - Incorrect: 9e-7, 1.5e+6, 1.23e-3
122
-
123
- This applies to all calculations, measurements, and numeric results in your response.
124
 
125
  Raw text:
126
  {raw_text}
@@ -193,7 +189,7 @@ Output JSON:
193
  json_start = llm_output.find("{")
194
  json_end = llm_output.rfind("}") + 1
195
  json_str = llm_output[json_start:json_end]
196
- structured_data = json.loads(json_str)
197
  structured_data_cache[text_hash] = structured_data
198
  logger.info(f"Gemini processing for {filename}, took {time.time() - start_time:.2f} seconds, {log_memory_usage()}")
199
  print("Structured Data", structured_data)
 
18
  import hashlib
19
  import google.generativeai as genai
20
  from dotenv import load_dotenv
21
+ from decimal import Decimal
22
 
23
  app = FastAPI()
24
 
 
35
  logger.error("GOOGLE_API_KEY not set")
36
  raise HTTPException(status_code=500, detail="GOOGLE_API_KEY not set")
37
  genai.configure(api_key=api_key)
38
+ model = genai.GenerativeModel("gemini-2.5-flash")
39
 
40
  # Set Tesseract path
41
  pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
 
117
  - The 'items' list may have multiple entries, each with detailed attributes.
118
  - If a field is missing or not found, return an empty value (`""` or `0`) and set `accuracy` to `0.0`.
119
  - Convert any date found in format : YYYY-MM-DD
 
 
 
 
 
120
 
121
  Raw text:
122
  {raw_text}
 
189
  json_start = llm_output.find("{")
190
  json_end = llm_output.rfind("}") + 1
191
  json_str = llm_output[json_start:json_end]
192
+ structured_data = json.loads(json_str, parse_float=Decimal)
193
  structured_data_cache[text_hash] = structured_data
194
  logger.info(f"Gemini processing for {filename}, took {time.time() - start_time:.2f} seconds, {log_memory_usage()}")
195
  print("Structured Data", structured_data)