pandora-s commited on
Commit
e82221d
·
verified ·
1 Parent(s): 32e43ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -43,7 +43,7 @@ def get_content_type(url):
43
 
44
  def perform_ocr_file(file, ocr_method="Mistral OCR"):
45
  if ocr_method == "Mistral OCR":
46
- if file.name.endswith('.pdf'):
47
  uploaded_pdf = client.files.upload(
48
  file={
49
  "file_name": file.name,
@@ -62,7 +62,7 @@ def perform_ocr_file(file, ocr_method="Mistral OCR"):
62
  )
63
  client.files.delete(file_id=uploaded_pdf.id)
64
 
65
- elif file.name.endswith(('.png', '.jpg', '.jpeg')):
66
  base64_image = encode_image(file.name)
67
  ocr_response = client.ocr.process(
68
  model="mistral-ocr-latest",
@@ -72,7 +72,8 @@ def perform_ocr_file(file, ocr_method="Mistral OCR"):
72
  },
73
  include_image_base64=True
74
  )
75
-
 
76
  combined_markdown, raw_markdown = get_combined_markdown(ocr_response)
77
  return combined_markdown, raw_markdown
78
 
 
43
 
44
  def perform_ocr_file(file, ocr_method="Mistral OCR"):
45
  if ocr_method == "Mistral OCR":
46
+ if lower(file.name).endswith('.pdf'):
47
  uploaded_pdf = client.files.upload(
48
  file={
49
  "file_name": file.name,
 
62
  )
63
  client.files.delete(file_id=uploaded_pdf.id)
64
 
65
+ elif lower(file.name).endswith(('.png', '.jpg', '.jpeg')):
66
  base64_image = encode_image(file.name)
67
  ocr_response = client.ocr.process(
68
  model="mistral-ocr-latest",
 
72
  },
73
  include_image_base64=True
74
  )
75
+ else:
76
+ return "# Unsupported file type. Please provide a PDF or an image (png, jpeg, jpg).", ""
77
  combined_markdown, raw_markdown = get_combined_markdown(ocr_response)
78
  return combined_markdown, raw_markdown
79