Spaces:
Runtime error
Runtime error
Fix missing tab after first exception
Browse files
app.py
CHANGED
|
@@ -42,16 +42,16 @@ def ocr_pdf_img_document(pdf_or_img_url:str)-> str:
|
|
| 42 |
}
|
| 43 |
)
|
| 44 |
except Exception:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
return "\n\n".join([f"### Page {i+1}\n{ocr_response.pages[i].markdown}" for i in range(len(ocr_response.pages))])
|
| 56 |
|
| 57 |
@tool
|
|
|
|
| 42 |
}
|
| 43 |
)
|
| 44 |
except Exception:
|
| 45 |
+
try: # IF PDF OCR fails, try Image OCR
|
| 46 |
+
ocr_response = client.ocr.process(
|
| 47 |
+
model=ocr_model,
|
| 48 |
+
document={
|
| 49 |
+
"type": "image_url",
|
| 50 |
+
"image_url": pdf_or_img_url
|
| 51 |
+
}
|
| 52 |
+
)
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return e # Return the error to the model if it fails, otherwise return the contents
|
| 55 |
return "\n\n".join([f"### Page {i+1}\n{ocr_response.pages[i].markdown}" for i in range(len(ocr_response.pages))])
|
| 56 |
|
| 57 |
@tool
|