devZenaight commited on
Commit
2d505ed
Β·
1 Parent(s): d27ed7a

updated python

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -7,6 +7,7 @@ from PIL import Image
7
  import base64
8
  import uvicorn
9
  import os
 
10
 
11
  from langchain_openai import ChatOpenAI
12
  from langchain.prompts import ChatPromptTemplate
@@ -20,9 +21,9 @@ os.makedirs("receiptimages", exist_ok=True)
20
  # Load trained YOLOv8n model
21
  model = YOLO("receipt-scanner/models/best.pt")
22
 
23
- # Init LangChain with GPT-5.1-nano
24
  llm = ChatOpenAI(
25
- model="gpt-5-nano",
26
  temperature=0,
27
  )
28
 
@@ -39,7 +40,7 @@ Return your answer strictly as JSON with keys: venue, date, total, category.
39
  """)
40
 
41
  def run_langchain_with_image(image_path: str):
42
- """Send a cropped receipt to GPT-5.1-nano via LangChain."""
43
  with open(image_path, "rb") as f:
44
  b64_image = base64.b64encode(f.read()).decode("utf-8")
45
 
@@ -49,6 +50,12 @@ def run_langchain_with_image(image_path: str):
49
  {"type": "image_url", "image_url": f"data:image/jpeg;base64,{b64_image}"}
50
  ]
51
  })
 
 
 
 
 
 
52
  return result.content
53
 
54
  @app.post("/process-receipt")
@@ -82,6 +89,9 @@ async def process_receipt(file: UploadFile = File(...)):
82
  "extracted": llm_result
83
  })
84
 
 
 
 
85
  return {"status": "success", "receipts": outputs}
86
 
87
  if __name__ == "__main__":
 
7
  import base64
8
  import uvicorn
9
  import os
10
+ import json
11
 
12
  from langchain_openai import ChatOpenAI
13
  from langchain.prompts import ChatPromptTemplate
 
21
  # Load trained YOLOv8n model
22
  model = YOLO("receipt-scanner/models/best.pt")
23
 
24
+ # Init LangChain with OpenAI (βœ… fixed model name)
25
  llm = ChatOpenAI(
26
+ model="gpt-4o-mini", # use a valid model
27
  temperature=0,
28
  )
29
 
 
40
  """)
41
 
42
  def run_langchain_with_image(image_path: str):
43
+ """Send a cropped receipt to GPT via LangChain and log details."""
44
  with open(image_path, "rb") as f:
45
  b64_image = base64.b64encode(f.read()).decode("utf-8")
46
 
 
50
  {"type": "image_url", "image_url": f"data:image/jpeg;base64,{b64_image}"}
51
  ]
52
  })
53
+
54
+ # πŸ”₯ Debug logging
55
+ print(f"πŸ–ΌοΈ Sent {len(b64_image)} base64 chars to GPT for {image_path}")
56
+ print(f"πŸ“€ GPT raw response: {result}")
57
+ print(f"πŸ“„ Extracted content: {result.content}")
58
+
59
  return result.content
60
 
61
  @app.post("/process-receipt")
 
89
  "extracted": llm_result
90
  })
91
 
92
+ # πŸ”₯ Log the full outputs for debugging
93
+ print("πŸ“¦ Final API response:", json.dumps(outputs, indent=2))
94
+
95
  return {"status": "success", "receipts": outputs}
96
 
97
  if __name__ == "__main__":