Synced repo using 'sync_with_huggingface' Github Action
Browse filesoriginal:
- remote: "https://github.com/xiaoyao9184/docker-surya"
- commit: "eea6e7264d22ed4964d2249c70b8cbe1f9db48d4"
sync_with_huggingface:
- repository: ""
- ref: ""
- gradio_app.py +24 -2
gradio_app.py
CHANGED
@@ -11,10 +11,11 @@ if "APP_PATH" in os.environ:
|
|
11 |
|
12 |
import io
|
13 |
import tempfile
|
14 |
-
from typing import List
|
15 |
|
16 |
import pypdfium2
|
17 |
import gradio as gr
|
|
|
|
|
18 |
|
19 |
from surya.common.surya.schema import TaskNames
|
20 |
from surya.models import load_predictors
|
@@ -221,7 +222,9 @@ with gr.Blocks(title="Surya") as demo:
|
|
221 |
- If OCR doesn't work, try changing the resolution of your image (increase if below 2048px width, otherwise decrease).
|
222 |
- This supports 90+ languages, see [here](https://github.com/VikParuchuri/surya/tree/master/surya/languages.py) for a full list.
|
223 |
|
224 |
-
Find the project [here](https://github.com/VikParuchuri/surya).
|
|
|
|
|
225 |
""")
|
226 |
|
227 |
with gr.Row():
|
@@ -290,6 +293,10 @@ with gr.Blocks(title="Surya") as demo:
|
|
290 |
|
291 |
# Run Text Detection
|
292 |
def text_det_img(pil_image):
|
|
|
|
|
|
|
|
|
293 |
det_img, pred = text_detection(pil_image)
|
294 |
det_json = pred.model_dump(exclude=["heatmap", "affinity_map"])
|
295 |
return (
|
@@ -304,6 +311,10 @@ with gr.Blocks(title="Surya") as demo:
|
|
304 |
|
305 |
# Run layout
|
306 |
def layout_det_img(pil_image):
|
|
|
|
|
|
|
|
|
307 |
layout_img, pred = layout_detection(pil_image)
|
308 |
layout_json = pred.model_dump(exclude=["segmentation_map"])
|
309 |
return (
|
@@ -318,6 +329,10 @@ with gr.Blocks(title="Surya") as demo:
|
|
318 |
|
319 |
# Run OCR
|
320 |
def text_rec_img(pil_image, in_file, page_number, skip_text_detection, recognize_math, ocr_with_boxes):
|
|
|
|
|
|
|
|
|
321 |
if in_file.endswith('.pdf'):
|
322 |
pil_image_highres = get_page_image(in_file, page_number, dpi=settings.IMAGE_DPI_HIGHRES)
|
323 |
else:
|
@@ -343,6 +358,9 @@ with gr.Blocks(title="Surya") as demo:
|
|
343 |
|
344 |
# Run Table Recognition
|
345 |
def table_rec_img(pil_image, in_file, page_number, skip_table_detection):
|
|
|
|
|
|
|
346 |
if in_file.endswith('.pdf'):
|
347 |
pil_image_highres = get_page_image(in_file, page_number, dpi=settings.IMAGE_DPI_HIGHRES)
|
348 |
else:
|
@@ -361,6 +379,10 @@ with gr.Blocks(title="Surya") as demo:
|
|
361 |
|
362 |
# Run bad PDF text detection
|
363 |
def ocr_errors_pdf(in_file):
|
|
|
|
|
|
|
|
|
364 |
if not in_file.endswith('.pdf'):
|
365 |
raise gr.Error("This feature only works with PDFs.", duration=5)
|
366 |
page_count = page_counter(in_file)
|
|
|
11 |
|
12 |
import io
|
13 |
import tempfile
|
|
|
14 |
|
15 |
import pypdfium2
|
16 |
import gradio as gr
|
17 |
+
import requests
|
18 |
+
from contextlib import suppress
|
19 |
|
20 |
from surya.common.surya.schema import TaskNames
|
21 |
from surya.models import load_predictors
|
|
|
222 |
- If OCR doesn't work, try changing the resolution of your image (increase if below 2048px width, otherwise decrease).
|
223 |
- This supports 90+ languages, see [here](https://github.com/VikParuchuri/surya/tree/master/surya/languages.py) for a full list.
|
224 |
|
225 |
+
Find the original project [here](https://github.com/VikParuchuri/surya).
|
226 |
+
Or this project [here](https://github.com/xiaoyao9184/docker-surya).
|
227 |
+
See the [README](./blob/main/README.md) for Spaces's metadata.
|
228 |
""")
|
229 |
|
230 |
with gr.Row():
|
|
|
293 |
|
294 |
# Run Text Detection
|
295 |
def text_det_img(pil_image):
|
296 |
+
# update counter
|
297 |
+
with suppress(Exception):
|
298 |
+
requests.get("https://counterapi.com/api/xiaoyao9184.github.com/view/docker-surya")
|
299 |
+
|
300 |
det_img, pred = text_detection(pil_image)
|
301 |
det_json = pred.model_dump(exclude=["heatmap", "affinity_map"])
|
302 |
return (
|
|
|
311 |
|
312 |
# Run layout
|
313 |
def layout_det_img(pil_image):
|
314 |
+
# update counter
|
315 |
+
with suppress(Exception):
|
316 |
+
requests.get("https://counterapi.com/api/xiaoyao9184.github.com/view/docker-surya")
|
317 |
+
|
318 |
layout_img, pred = layout_detection(pil_image)
|
319 |
layout_json = pred.model_dump(exclude=["segmentation_map"])
|
320 |
return (
|
|
|
329 |
|
330 |
# Run OCR
|
331 |
def text_rec_img(pil_image, in_file, page_number, skip_text_detection, recognize_math, ocr_with_boxes):
|
332 |
+
# update counter
|
333 |
+
with suppress(Exception):
|
334 |
+
requests.get("https://counterapi.com/api/xiaoyao9184.github.com/view/docker-surya")
|
335 |
+
|
336 |
if in_file.endswith('.pdf'):
|
337 |
pil_image_highres = get_page_image(in_file, page_number, dpi=settings.IMAGE_DPI_HIGHRES)
|
338 |
else:
|
|
|
358 |
|
359 |
# Run Table Recognition
|
360 |
def table_rec_img(pil_image, in_file, page_number, skip_table_detection):
|
361 |
+
# update counter
|
362 |
+
with suppress(Exception):
|
363 |
+
requests.get("https://counterapi.com/api/xiaoyao9184.github.com/view/docker-surya")
|
364 |
if in_file.endswith('.pdf'):
|
365 |
pil_image_highres = get_page_image(in_file, page_number, dpi=settings.IMAGE_DPI_HIGHRES)
|
366 |
else:
|
|
|
379 |
|
380 |
# Run bad PDF text detection
|
381 |
def ocr_errors_pdf(in_file):
|
382 |
+
# update counter
|
383 |
+
with suppress(Exception):
|
384 |
+
requests.get("https://counterapi.com/api/xiaoyao9184.github.com/view/docker-surya")
|
385 |
+
|
386 |
if not in_file.endswith('.pdf'):
|
387 |
raise gr.Error("This feature only works with PDFs.", duration=5)
|
388 |
page_count = page_counter(in_file)
|