02alexander commited on
Commit
fb2cfa5
·
0 Parent(s):

initial commit

Browse files
Files changed (10) hide show
  1. .gitignore +3 -0
  2. .mypy.ini +12 -0
  3. README.md +10 -0
  4. app.py +50 -0
  5. examples/RP2040.png +0 -0
  6. examples/lorem-ipsum.png +0 -0
  7. examples/paper.png +0 -0
  8. lychee.toml +82 -0
  9. pyproject.toml +72 -0
  10. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ shell.nix
2
+ __pycache__/
3
+ venv/
.mypy.ini ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [mypy]
2
+ files = .
3
+ exclude = build
4
+ namespace_packages = True
5
+ show_error_codes = True
6
+ strict = True
7
+ enable_error_code = redundant-expr, truthy-bool, ignore-without-code
8
+ ; plugins = numpy.typing.mypy_plugin
9
+ ignore_missing_imports = True
10
+ no_implicit_reexport = False
11
+ disallow_untyped_calls = False
12
+ ignore_missing_imports = True
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: OCR
3
+ emoji: 🔥
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 4.36.1
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from pathlib import Path
5
+
6
+ import gradio as gr # type: ignore
7
+ import rerun as rr
8
+ import rerun.blueprint as rrb
9
+ from gradio_rerun import Rerun # type: ignore
10
+ from ocr import detect_and_log_layout # type: ignore
11
+
12
+
13
+ @rr.thread_local_stream("PaddleOCR")
14
+ def log_to_rr(img_path: Path):
15
+ print(img_path)
16
+ stream = rr.binary_stream()
17
+
18
+ blueprint = rrb.Blueprint(
19
+ rrb.Vertical(
20
+ rrb.Spatial2DView(name="Input", contents=["Image/**"]),
21
+ ),
22
+ collapse_panels=True,
23
+ )
24
+ rr.send_blueprint(blueprint)
25
+
26
+ detect_and_log_layout(img_path)
27
+
28
+ yield stream.read()
29
+
30
+
31
+ with gr.Blocks() as demo:
32
+ with gr.Row():
33
+ with gr.Column(scale=1):
34
+ with gr.Row():
35
+ input_image = gr.Image(label="Input Image", image_mode="RGBA", sources="upload", type="filepath")
36
+ with gr.Row():
37
+ button = gr.Button()
38
+ with gr.Row():
39
+ gr.Examples(
40
+ examples=[os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))],
41
+ inputs=[input_image],
42
+ label="Examples",
43
+ cache_examples=False,
44
+ examples_per_page=12,
45
+ )
46
+ with gr.Column(scale=4):
47
+ viewer = Rerun(streaming=True, height=900)
48
+ button.click(log_to_rr, inputs=[input_image], outputs=[viewer])
49
+
50
+ demo.launch()
examples/RP2040.png ADDED
examples/lorem-ipsum.png ADDED
examples/paper.png ADDED
lychee.toml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copied from https://github.com/rerun-io/rerun_template
2
+
3
+ ################################################################################
4
+ # Config for the link checker lychee.
5
+ #
6
+ # Download & learn more at:
7
+ # https://github.com/lycheeverse/lychee
8
+ #
9
+ # Example config:
10
+ # https://github.com/lycheeverse/lychee/blob/master/lychee.example.toml
11
+ #
12
+ # Run `lychee . --dump` to list all found links that are being checked.
13
+ #
14
+ # Note that by default lychee will only check markdown and html files,
15
+ # to check any other files you have to point to them explicitly, e.g.:
16
+ # `lychee **/*.rs`
17
+ # To make things worse, `exclude_path` is ignored for these globs,
18
+ # so local runs with lots of gitignored files will be slow.
19
+ # (https://github.com/lycheeverse/lychee/issues/1405)
20
+ #
21
+ # This unfortunately doesn't list anything for non-glob checks.
22
+ ################################################################################
23
+
24
+ # Maximum number of concurrent link checks.
25
+ # Workaround for "too many open files" error on MacOS, see https://github.com/lycheeverse/lychee/issues/1248
26
+ max_concurrency = 32
27
+
28
+ # Check links inside `<code>` and `<pre>` blocks as well as Markdown code blocks.
29
+ include_verbatim = true
30
+
31
+ # Proceed for server connections considered insecure (invalid TLS).
32
+ insecure = true
33
+
34
+ # Exclude these filesystem paths from getting checked.
35
+ exclude_path = [
36
+ # Unfortunately lychee doesn't yet read .gitignore https://github.com/lycheeverse/lychee/issues/1331
37
+ # The following entries are there because of that:
38
+ ".git",
39
+ "__pycache__",
40
+ "_deps/",
41
+ ".pixi",
42
+ "build",
43
+ "target_ra",
44
+ "target_wasm",
45
+ "target",
46
+ "venv",
47
+ ]
48
+
49
+ # Exclude URLs and mail addresses from checking (supports regex).
50
+ exclude = [
51
+ # Skip speculative links
52
+ '.*?speculative-link',
53
+
54
+ # Strings with replacements.
55
+ '/__VIEWER_VERSION__/', # Replacement variable __VIEWER_VERSION__.
56
+ '/\$', # Replacement variable $.
57
+ '/GIT_HASH/', # Replacement variable GIT_HASH.
58
+ '\{\}', # Ignore links with string interpolation.
59
+ '\$relpath\^', # Relative paths as used by rerun_cpp's doc header.
60
+ '%7B.+%7D', # Ignore strings that look like ready to use links but contain a replacement strings. The URL escaping is for '{.+}' (this seems to be needed for html embedded urls since lychee assumes they use this encoding).
61
+ '%7B%7D', # Ignore links with string interpolation, escaped variant.
62
+
63
+ # Local links that require further setup.
64
+ 'http://127.0.0.1',
65
+ 'http://localhost',
66
+ 'recording:/', # rrd recording link.
67
+ 'ws:/',
68
+ 're_viewer.js', # Build artifact that html is linking to.
69
+
70
+ # Api endpoints.
71
+ 'https://fonts.googleapis.com/', # Font API entrypoint, not a link.
72
+ 'https://fonts.gstatic.com/', # Font API entrypoint, not a link.
73
+ 'https://tel.rerun.io/', # Analytics endpoint.
74
+
75
+ # Avoid rate limiting.
76
+ 'https://crates.io/crates/.*', # Avoid crates.io rate-limiting
77
+ 'https://github.com/rerun-io/rerun/commit/\.*', # Ignore links to our own commits (typically in changelog).
78
+ 'https://github.com/rerun-io/rerun/pull/\.*', # Ignore links to our own pull requests (typically in changelog).
79
+
80
+ # Used in rerun_template repo until the user search-replaces `new_repo_name`
81
+ 'https://github.com/rerun-io/new_repo_name',
82
+ ]
pyproject.toml ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copied from https://github.com/rerun-io/rerun_template
2
+
3
+ [tool.ruff]
4
+ # https://beta.ruff.rs/docs/configuration/
5
+
6
+ target-version = "py38"
7
+
8
+ # Enable unsafe fixes to allow ruff to apply fixes that may change the behavior of the code.
9
+ # This is needed because otherwise ruff will not be able to trim whitespaces in (codegened) docstrings.
10
+ unsafe-fixes = true
11
+
12
+ # Allow preview lints to be enabled (like `PLW1514` to force `encoding` on open).
13
+ preview = true
14
+ # But we only want to opt-in to certain preview rules!
15
+ lint.explicit-preview-rules = true
16
+
17
+ extend-exclude = [
18
+ # Automatically generated test artifacts
19
+ "venv/",
20
+ "target/",
21
+ ]
22
+
23
+ lint.ignore = [
24
+ # These makes sense to ignore in example code, but for a proper library we should not ignore these.
25
+ "D100", # Missing docstring in public module
26
+ "D101", # Missing docstring in public class
27
+ "D103", # Missing docstring in public function
28
+
29
+ # No blank lines allowed after function docstring.
30
+ "D202",
31
+
32
+ # npydocstyle: http://www.pydocstyle.org/en/stable/error_codes.html
33
+ # numpy convention with a few additional lints
34
+ "D107",
35
+ "D203",
36
+ "D212",
37
+ "D401",
38
+ "D402",
39
+ "D415",
40
+ "D416",
41
+
42
+ # Ruff can't fix this error on its own (yet)
43
+ # Having ruff check this causes errors that prevent the code-formatting process from completing.
44
+ "E501",
45
+
46
+ # allow relative imports
47
+ "TID252",
48
+
49
+ "UP007", # We need this, or `ruff format` will convert `Union[X, Y]` to `X | Y` which break on Python 3.8
50
+ ]
51
+
52
+ line-length = 120
53
+ lint.select = [
54
+ "D", # pydocstyle codes https://www.pydocstyle.org/en/latest/error_codes.html
55
+ "E", # pycodestyle error codes: https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
56
+ "F", # Flake8 error codes https://flake8.pycqa.org/en/latest/user/error-codes.html
57
+ "I", # Isort
58
+ "TID", # flake8-tidy-imports
59
+ "W", # pycodestyle warning codes: https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
60
+ "UP", # pyupgrade (ensures idomatic code for supported python version)
61
+ "PLW1514", # Force setting `encoding` for open calls. This is in order to prevent issues when opening utf8 files on windows where the default encoding may depend on the active locale. https://docs.astral.sh/ruff/rules/unspecified-encoding/
62
+ ]
63
+
64
+ lint.unfixable = [
65
+ "PLW1514", # Automatic fix for `encoding` doesn't do what we want - it queries the locale for the preferred encoding which is exactly what we want to avoid.
66
+ ]
67
+
68
+ [tool.ruff.lint.per-file-ignores]
69
+ "__init__.py" = ["F401", "F403"]
70
+
71
+ [tool.ruff.lint.isort]
72
+ required-imports = ["from __future__ import annotations"]
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ rerun-sdk>=0.16.0,<0.17.0
2
+ spaces
3
+ gradio
4
+ gradio_rerun
5
+ git+https://github.com/rerun-io/rerun.git@c5f817686c6a1b8723ddeee25a9aed0ff4fa1e92#egg=ocr&subdirectory=examples/python/ocr