hysts HF staff commited on
Commit
2953d5a
·
1 Parent(s): a4f33f6
Files changed (5) hide show
  1. .pre-commit-config.yaml +59 -34
  2. .style.yapf +0 -5
  3. .vscode/settings.json +30 -0
  4. app.py +13 -15
  5. style.css +4 -0
.pre-commit-config.yaml CHANGED
@@ -1,35 +1,60 @@
1
  repos:
2
- - repo: https://github.com/pre-commit/pre-commit-hooks
3
- rev: v4.2.0
4
- hooks:
5
- - id: check-executables-have-shebangs
6
- - id: check-json
7
- - id: check-merge-conflict
8
- - id: check-shebang-scripts-are-executable
9
- - id: check-toml
10
- - id: check-yaml
11
- - id: double-quote-string-fixer
12
- - id: end-of-file-fixer
13
- - id: mixed-line-ending
14
- args: ['--fix=lf']
15
- - id: requirements-txt-fixer
16
- - id: trailing-whitespace
17
- - repo: https://github.com/myint/docformatter
18
- rev: v1.4
19
- hooks:
20
- - id: docformatter
21
- args: ['--in-place']
22
- - repo: https://github.com/pycqa/isort
23
- rev: 5.12.0
24
- hooks:
25
- - id: isort
26
- - repo: https://github.com/pre-commit/mirrors-mypy
27
- rev: v0.991
28
- hooks:
29
- - id: mypy
30
- args: ['--ignore-missing-imports']
31
- - repo: https://github.com/google/yapf
32
- rev: v0.32.0
33
- hooks:
34
- - id: yapf
35
- args: ['--parallel', '--in-place']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.0
4
+ hooks:
5
+ - id: check-executables-have-shebangs
6
+ - id: check-json
7
+ - id: check-merge-conflict
8
+ - id: check-shebang-scripts-are-executable
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: end-of-file-fixer
12
+ - id: mixed-line-ending
13
+ args: ["--fix=lf"]
14
+ - id: requirements-txt-fixer
15
+ - id: trailing-whitespace
16
+ - repo: https://github.com/myint/docformatter
17
+ rev: v1.7.5
18
+ hooks:
19
+ - id: docformatter
20
+ args: ["--in-place"]
21
+ - repo: https://github.com/pycqa/isort
22
+ rev: 5.13.2
23
+ hooks:
24
+ - id: isort
25
+ args: ["--profile", "black"]
26
+ - repo: https://github.com/pre-commit/mirrors-mypy
27
+ rev: v1.10.0
28
+ hooks:
29
+ - id: mypy
30
+ args: ["--ignore-missing-imports"]
31
+ additional_dependencies:
32
+ [
33
+ "types-python-slugify",
34
+ "types-requests",
35
+ "types-PyYAML",
36
+ "types-pytz",
37
+ ]
38
+ - repo: https://github.com/psf/black
39
+ rev: 24.4.2
40
+ hooks:
41
+ - id: black
42
+ language_version: python3.10
43
+ args: ["--line-length", "119"]
44
+ - repo: https://github.com/kynan/nbstripout
45
+ rev: 0.7.1
46
+ hooks:
47
+ - id: nbstripout
48
+ args:
49
+ [
50
+ "--extra-keys",
51
+ "metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
52
+ ]
53
+ - repo: https://github.com/nbQA-dev/nbQA
54
+ rev: 1.8.5
55
+ hooks:
56
+ - id: nbqa-black
57
+ - id: nbqa-pyupgrade
58
+ args: ["--py37-plus"]
59
+ - id: nbqa-isort
60
+ args: ["--float-to-top"]
.style.yapf DELETED
@@ -1,5 +0,0 @@
1
- [style]
2
- based_on_style = pep8
3
- blank_line_before_nested_class_or_def = false
4
- spaces_before_comment = 2
5
- split_before_logical_operator = true
 
 
 
 
 
 
.vscode/settings.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "files.insertFinalNewline": false,
4
+ "[python]": {
5
+ "editor.defaultFormatter": "ms-python.black-formatter",
6
+ "editor.formatOnType": true,
7
+ "editor.codeActionsOnSave": {
8
+ "source.organizeImports": "explicit"
9
+ }
10
+ },
11
+ "[jupyter]": {
12
+ "files.insertFinalNewline": false
13
+ },
14
+ "black-formatter.args": [
15
+ "--line-length=119"
16
+ ],
17
+ "isort.args": ["--profile", "black"],
18
+ "flake8.args": [
19
+ "--max-line-length=119"
20
+ ],
21
+ "ruff.lint.args": [
22
+ "--line-length=119"
23
+ ],
24
+ "notebook.output.scrolling": true,
25
+ "notebook.formatOnCellExecution": true,
26
+ "notebook.formatOnSave.enabled": true,
27
+ "notebook.codeActionsOnSave": {
28
+ "source.organizeImports": "explicit"
29
+ }
30
+ }
app.py CHANGED
@@ -11,17 +11,17 @@ import gradio as gr
11
  import PIL.Image
12
  from manga_ocr import MangaOcr
13
 
14
- DESCRIPTION = '# [Manga OCR](https://github.com/kha-white/manga-ocr)'
15
 
16
 
17
  def download_sample_images() -> list[pathlib.Path]:
18
- image_dir = pathlib.Path('images')
19
  if not image_dir.exists():
20
  image_dir.mkdir()
21
  for index in range(12):
22
- url = f'https://raw.githubusercontent.com/kha-white/manga-ocr/master/assets/examples/{index:02d}.jpg'
23
- urllib.request.urlretrieve(url, image_dir / f'{index:02d}.jpg')
24
- return sorted(image_dir.rglob('*.jpg'))
25
 
26
 
27
  def run(image: PIL.Image.Image, mocr: MangaOcr) -> str:
@@ -34,18 +34,16 @@ fn = functools.partial(run, mocr=mocr)
34
  image_paths = download_sample_images()
35
  examples = [[path.as_posix()] for path in image_paths]
36
 
37
- with gr.Blocks(css='style.css') as demo:
38
  gr.Markdown(DESCRIPTION)
39
  with gr.Row():
40
  with gr.Column():
41
- image = gr.Image(label='Input', type='pil')
42
- run_button = gr.Button('Run')
43
  with gr.Column():
44
- result = gr.Text(label='Output')
45
- gr.Examples(examples=examples,
46
- inputs=image,
47
- outputs=result,
48
- fn=fn,
49
- cache_examples=os.getenv('CACHE_EXAMPLES') == '1')
50
- run_button.click(fn=fn, inputs=image, outputs=result, api_name='run')
51
  demo.queue().launch()
 
11
  import PIL.Image
12
  from manga_ocr import MangaOcr
13
 
14
+ DESCRIPTION = "# [Manga OCR](https://github.com/kha-white/manga-ocr)"
15
 
16
 
17
  def download_sample_images() -> list[pathlib.Path]:
18
+ image_dir = pathlib.Path("images")
19
  if not image_dir.exists():
20
  image_dir.mkdir()
21
  for index in range(12):
22
+ url = f"https://raw.githubusercontent.com/kha-white/manga-ocr/master/assets/examples/{index:02d}.jpg"
23
+ urllib.request.urlretrieve(url, image_dir / f"{index:02d}.jpg")
24
+ return sorted(image_dir.rglob("*.jpg"))
25
 
26
 
27
  def run(image: PIL.Image.Image, mocr: MangaOcr) -> str:
 
34
  image_paths = download_sample_images()
35
  examples = [[path.as_posix()] for path in image_paths]
36
 
37
+ with gr.Blocks(css="style.css") as demo:
38
  gr.Markdown(DESCRIPTION)
39
  with gr.Row():
40
  with gr.Column():
41
+ image = gr.Image(label="Input", type="pil")
42
+ run_button = gr.Button("Run")
43
  with gr.Column():
44
+ result = gr.Text(label="Output")
45
+ gr.Examples(
46
+ examples=examples, inputs=image, outputs=result, fn=fn, cache_examples=os.getenv("CACHE_EXAMPLES") == "1"
47
+ )
48
+ run_button.click(fn=fn, inputs=image, outputs=result, api_name="run")
 
 
49
  demo.queue().launch()
style.css CHANGED
@@ -1,7 +1,11 @@
1
  h1 {
2
  text-align: center;
 
3
  }
4
 
5
  #duplicate-button {
6
  margin: auto;
 
 
 
7
  }
 
1
  h1 {
2
  text-align: center;
3
+ display: block;
4
  }
5
 
6
  #duplicate-button {
7
  margin: auto;
8
+ color: #fff;
9
+ background: #1565c0;
10
+ border-radius: 100vh;
11
  }