Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,11 +24,11 @@ def image_to_base64(image):
|
|
| 24 |
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 25 |
|
| 26 |
|
| 27 |
-
def render_pdf_page(page, max_resolution=
|
| 28 |
width, height = page.get_size()
|
| 29 |
pixel_width = width * scale
|
| 30 |
pixel_height = height * scale
|
| 31 |
-
resize_factor = min(max_resolution / pixel_width, max_resolution / pixel_height)
|
| 32 |
target_scale = scale * resize_factor
|
| 33 |
return page.render(scale=target_scale, rev_byteorder=True).to_pil()
|
| 34 |
|
|
@@ -176,8 +176,7 @@ with gr.Blocks(title="π Image/PDF OCR", theme=gr.themes.Soft()) as demo:
|
|
| 176 |
# π Image/PDF to Text Extraction
|
| 177 |
**π‘ How to use:**
|
| 178 |
1. Upload an image OR a PDF (max 5 pages)
|
| 179 |
-
2.
|
| 180 |
-
3. Click "Extract Text" to process
|
| 181 |
|
| 182 |
The model will extract and format text from your document.
|
| 183 |
"""
|
|
|
|
| 24 |
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 25 |
|
| 26 |
|
| 27 |
+
def render_pdf_page(page, max_resolution=1540, scale=2.77):
|
| 28 |
width, height = page.get_size()
|
| 29 |
pixel_width = width * scale
|
| 30 |
pixel_height = height * scale
|
| 31 |
+
resize_factor = min(1, max_resolution / pixel_width, max_resolution / pixel_height)
|
| 32 |
target_scale = scale * resize_factor
|
| 33 |
return page.render(scale=target_scale, rev_byteorder=True).to_pil()
|
| 34 |
|
|
|
|
| 176 |
# π Image/PDF to Text Extraction
|
| 177 |
**π‘ How to use:**
|
| 178 |
1. Upload an image OR a PDF (max 5 pages)
|
| 179 |
+
2. Click "Extract Text" to process
|
|
|
|
| 180 |
|
| 181 |
The model will extract and format text from your document.
|
| 182 |
"""
|