Seth0330 commited on
Commit
ee0b32d
·
verified ·
1 Parent(s): 77a95c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
  import time
4
  import os
5
 
6
- # CONFIG — Edit if you want to move to environment variables instead of hard-coding
7
  UNSTRACT_API_KEY = os.getenv("UNSTRACT_API_KEY", "pktmL5lfqlVv7IWW_MYhdXRl399GA1n8vaLktHefxVY")
8
  BASE_URL = "https://llmwhisperer-api.us-central.unstract.com/api/v2"
9
 
@@ -12,10 +12,16 @@ def upload_pdf_to_unstract(pdf_file):
12
  headers = {
13
  "unstract-key": UNSTRACT_API_KEY,
14
  }
 
 
 
15
  files = {
16
- "file": (pdf_file.name, pdf_file, "application/pdf"),
 
 
 
 
17
  }
18
- # 'mode': 'form' is not required, default is 'native_text'
19
  with st.spinner("Uploading and starting OCR..."):
20
  resp = requests.post(url, headers=headers, files=files)
21
  if resp.status_code not in (200, 202):
 
3
  import time
4
  import os
5
 
6
+ # CONFIG
7
  UNSTRACT_API_KEY = os.getenv("UNSTRACT_API_KEY", "pktmL5lfqlVv7IWW_MYhdXRl399GA1n8vaLktHefxVY")
8
  BASE_URL = "https://llmwhisperer-api.us-central.unstract.com/api/v2"
9
 
 
12
  headers = {
13
  "unstract-key": UNSTRACT_API_KEY,
14
  }
15
+ # Always reset file pointer and use "application/pdf"
16
+ pdf_file.seek(0)
17
+ file_bytes = pdf_file.read()
18
  files = {
19
+ "file": (
20
+ pdf_file.name if pdf_file.name.lower().endswith(".pdf") else "invoice.pdf",
21
+ file_bytes,
22
+ "application/pdf"
23
+ ),
24
  }
 
25
  with st.spinner("Uploading and starting OCR..."):
26
  resp = requests.post(url, headers=headers, files=files)
27
  if resp.status_code not in (200, 202):