Sathvik-kota commited on
Commit
095a28c
·
verified ·
1 Parent(s): f7f8c22

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +37 -37
app.py CHANGED
@@ -599,49 +599,49 @@ async def extract_bill_data(payload: BillRequest):
599
  doc_url = payload.document
600
  file_bytes = None
601
 
602
- # ---------------------------
603
- # 1. LOCAL FILE SUPPORT
604
- # ---------------------------
605
- if doc_url.startswith("file://"):
606
- local_path = doc_url.replace("file://", "")
607
- try:
608
- with open(local_path, "rb") as f:
609
- file_bytes = f.read()
610
- except Exception as e:
611
- return {
612
- "is_success": False,
613
- "error": f"Local file read error: {e}",
614
- "data": {"pagewise_line_items": [], "total_item_count": 0},
615
- "token_usage": {"total_tokens": 0, "input_tokens": 0, "output_tokens": 0}
616
- }
617
-
618
- # ---------------------------
619
- # 2. REMOTE URL DOWNLOAD
620
- # ---------------------------
621
- else:
622
- try:
623
- headers = {"User-Agent": "Mozilla/5.0"}
624
- resp = requests.get(doc_url, headers=headers, timeout=30)
625
- if resp.status_code != 200:
626
- raise RuntimeError(f"Download failed status={resp.status_code}")
627
- file_bytes = resp.content
628
- except Exception as e:
 
 
 
 
 
 
 
 
 
629
  return {
630
  "is_success": False,
631
- "error": f"HTTP error: {e}",
632
  "data": {"pagewise_line_items": [], "total_item_count": 0},
633
  "token_usage": {"total_tokens": 0, "input_tokens": 0, "output_tokens": 0}
634
  }
635
 
636
- # Safety check
637
- if not file_bytes:
638
- return {
639
- "is_success": False,
640
- "error": "No file bytes found.",
641
- "data": {"pagewise_line_items": [], "total_item_count": 0},
642
- "token_usage": {"total_tokens": 0, "input_tokens": 0, "output_tokens": 0}
643
- }
644
-
645
  images = []
646
  clean_url = doc_url.split("?", 1)[0].lower()
647
  try:
 
599
  doc_url = payload.document
600
  file_bytes = None
601
 
602
+ # ---------------------------
603
+ # 1. LOCAL FILE SUPPORT
604
+ # ---------------------------
605
+ if doc_url.startswith("file://"):
606
+ local_path = doc_url.replace("file://", "")
607
+ try:
608
+ with open(local_path, "rb") as f:
609
+ file_bytes = f.read()
610
+ except Exception as e:
611
+ return {
612
+ "is_success": False,
613
+ "error": f"Local file read error: {e}",
614
+ "data": {"pagewise_line_items": [], "total_item_count": 0},
615
+ "token_usage": {"total_tokens": 0, "input_tokens": 0, "output_tokens": 0}
616
+ }
617
+
618
+ # ---------------------------
619
+ # 2. REMOTE URL DOWNLOAD
620
+ # ---------------------------
621
+ else:
622
+ try:
623
+ headers = {"User-Agent": "Mozilla/5.0"}
624
+ resp = requests.get(doc_url, headers=headers, timeout=30)
625
+ if resp.status_code != 200:
626
+ raise RuntimeError(f"Download failed status={resp.status_code}")
627
+ file_bytes = resp.content
628
+ except Exception as e:
629
+ return {
630
+ "is_success": False,
631
+ "error": f"HTTP error: {e}",
632
+ "data": {"pagewise_line_items": [], "total_item_count": 0},
633
+ "token_usage": {"total_tokens": 0, "input_tokens": 0, "output_tokens": 0}
634
+ }
635
+
636
+ # Final safety check
637
+ if not file_bytes:
638
  return {
639
  "is_success": False,
640
+ "error": "No file bytes found.",
641
  "data": {"pagewise_line_items": [], "total_item_count": 0},
642
  "token_usage": {"total_tokens": 0, "input_tokens": 0, "output_tokens": 0}
643
  }
644
 
 
 
 
 
 
 
 
 
 
645
  images = []
646
  clean_url = doc_url.split("?", 1)[0].lower()
647
  try: