JacobLinCool commited on
Commit
e73dc89
·
1 Parent(s): 1f8c0d9

feat: add app

Browse files
Files changed (7) hide show
  1. .gitignore +1 -0
  2. README.md +4 -3
  3. app.py +42 -0
  4. packages.txt +1 -0
  5. poetry.lock +0 -0
  6. pyproject.toml +21 -0
  7. requirements.txt +66 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv/
README.md CHANGED
@@ -1,13 +1,14 @@
1
  ---
2
  title: Image Binarization
3
- emoji: 🦀
4
  colorFrom: indigo
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.24.1
 
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Image Binarization
3
+ emoji: ✂️
4
  colorFrom: indigo
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 3.25.0
8
+ python_version: 3.11
9
  app_file: app.py
10
  pinned: false
11
  license: mit
12
  ---
13
 
14
+ Check out the configuration reference at <https://huggingface.co/docs/hub/spaces-config-reference>
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import cv2
4
+
5
+
6
+ def run(img: np.ndarray, thres: int) -> tuple[np.ndarray, int | str]:
7
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
8
+
9
+ if thres > 0:
10
+ _, img = cv2.threshold(img, thres, 255, cv2.THRESH_BINARY)
11
+ threshold = thres
12
+ elif thres < 0:
13
+ img = cv2.adaptiveThreshold(
14
+ img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, -thres
15
+ )
16
+ threshold = "adaptive"
17
+ else:
18
+ threshold, img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
19
+
20
+ return img, threshold
21
+
22
+
23
+ app = gr.Interface(
24
+ fn=run,
25
+ inputs=[
26
+ gr.Image(label="image"),
27
+ gr.Slider(
28
+ -30,
29
+ 255,
30
+ -2,
31
+ label="threshold",
32
+ info="0 for Otsu's method, negative for adaptive thresholding",
33
+ ),
34
+ ],
35
+ outputs=[
36
+ gr.Image(label="processed"),
37
+ gr.Label(label="threshold"),
38
+ ],
39
+ allow_flagging="never",
40
+ )
41
+
42
+ app.queue().launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python3-opencv
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "image-binarization"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["JacobLinCool <jacoblincool@gmail.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ packages = [{include = "image_binarization"}]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = "~3.11"
12
+ gradio = "^3.25.0"
13
+ opencv-python = "^4.7.0.72"
14
+ numpy = "^1.24.2"
15
+
16
+ [tool.poetry.group.dev.dependencies]
17
+ black = "^23.3.0"
18
+
19
+ [build-system]
20
+ requires = ["poetry-core"]
21
+ build-backend = "poetry.core.masonry.api"
requirements.txt ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.1.0 ; python_version >= "3.11" and python_version < "3.12"
2
+ aiohttp==3.8.4 ; python_version >= "3.11" and python_version < "3.12"
3
+ aiosignal==1.3.1 ; python_version >= "3.11" and python_version < "3.12"
4
+ altair==4.2.2 ; python_version >= "3.11" and python_version < "3.12"
5
+ anyio==3.6.2 ; python_version >= "3.11" and python_version < "3.12"
6
+ async-timeout==4.0.2 ; python_version >= "3.11" and python_version < "3.12"
7
+ attrs==22.2.0 ; python_version >= "3.11" and python_version < "3.12"
8
+ certifi==2022.12.7 ; python_version >= "3.11" and python_version < "3.12"
9
+ charset-normalizer==3.1.0 ; python_version >= "3.11" and python_version < "3.12"
10
+ click==8.1.3 ; python_version >= "3.11" and python_version < "3.12"
11
+ colorama==0.4.6 ; python_version >= "3.11" and python_version < "3.12" and platform_system == "Windows"
12
+ contourpy==1.0.7 ; python_version >= "3.11" and python_version < "3.12"
13
+ cycler==0.11.0 ; python_version >= "3.11" and python_version < "3.12"
14
+ entrypoints==0.4 ; python_version >= "3.11" and python_version < "3.12"
15
+ fastapi==0.95.0 ; python_version >= "3.11" and python_version < "3.12"
16
+ ffmpy==0.3.0 ; python_version >= "3.11" and python_version < "3.12"
17
+ filelock==3.11.0 ; python_version >= "3.11" and python_version < "3.12"
18
+ fonttools==4.39.3 ; python_version >= "3.11" and python_version < "3.12"
19
+ frozenlist==1.3.3 ; python_version >= "3.11" and python_version < "3.12"
20
+ fsspec==2023.4.0 ; python_version >= "3.11" and python_version < "3.12"
21
+ gradio-client==0.0.10 ; python_version >= "3.11" and python_version < "3.12"
22
+ gradio==3.25.0 ; python_version >= "3.11" and python_version < "3.12"
23
+ h11==0.14.0 ; python_version >= "3.11" and python_version < "3.12"
24
+ httpcore==0.17.0 ; python_version >= "3.11" and python_version < "3.12"
25
+ httpx==0.24.0 ; python_version >= "3.11" and python_version < "3.12"
26
+ huggingface-hub==0.13.4 ; python_version >= "3.11" and python_version < "3.12"
27
+ idna==3.4 ; python_version >= "3.11" and python_version < "3.12"
28
+ jinja2==3.1.2 ; python_version >= "3.11" and python_version < "3.12"
29
+ jsonschema==4.17.3 ; python_version >= "3.11" and python_version < "3.12"
30
+ kiwisolver==1.4.4 ; python_version >= "3.11" and python_version < "3.12"
31
+ linkify-it-py==2.0.0 ; python_version >= "3.11" and python_version < "3.12"
32
+ markdown-it-py==2.2.0 ; python_version >= "3.11" and python_version < "3.12"
33
+ markdown-it-py[linkify]==2.2.0 ; python_version >= "3.11" and python_version < "3.12"
34
+ markupsafe==2.1.2 ; python_version >= "3.11" and python_version < "3.12"
35
+ matplotlib==3.7.1 ; python_version >= "3.11" and python_version < "3.12"
36
+ mdit-py-plugins==0.3.3 ; python_version >= "3.11" and python_version < "3.12"
37
+ mdurl==0.1.2 ; python_version >= "3.11" and python_version < "3.12"
38
+ multidict==6.0.4 ; python_version >= "3.11" and python_version < "3.12"
39
+ numpy==1.24.2 ; python_version >= "3.11" and python_version < "3.12"
40
+ opencv-python==4.7.0.72 ; python_version >= "3.11" and python_version < "3.12"
41
+ orjson==3.8.10 ; python_version >= "3.11" and python_version < "3.12"
42
+ packaging==23.0 ; python_version >= "3.11" and python_version < "3.12"
43
+ pandas==2.0.0 ; python_version >= "3.11" and python_version < "3.12"
44
+ pillow==9.5.0 ; python_version >= "3.11" and python_version < "3.12"
45
+ pydantic==1.10.7 ; python_version >= "3.11" and python_version < "3.12"
46
+ pydub==0.25.1 ; python_version >= "3.11" and python_version < "3.12"
47
+ pyparsing==3.0.9 ; python_version >= "3.11" and python_version < "3.12"
48
+ pyrsistent==0.19.3 ; python_version >= "3.11" and python_version < "3.12"
49
+ python-dateutil==2.8.2 ; python_version >= "3.11" and python_version < "3.12"
50
+ python-multipart==0.0.6 ; python_version >= "3.11" and python_version < "3.12"
51
+ pytz==2023.3 ; python_version >= "3.11" and python_version < "3.12"
52
+ pyyaml==6.0 ; python_version >= "3.11" and python_version < "3.12"
53
+ requests==2.28.2 ; python_version >= "3.11" and python_version < "3.12"
54
+ semantic-version==2.10.0 ; python_version >= "3.11" and python_version < "3.12"
55
+ six==1.16.0 ; python_version >= "3.11" and python_version < "3.12"
56
+ sniffio==1.3.0 ; python_version >= "3.11" and python_version < "3.12"
57
+ starlette==0.26.1 ; python_version >= "3.11" and python_version < "3.12"
58
+ toolz==0.12.0 ; python_version >= "3.11" and python_version < "3.12"
59
+ tqdm==4.65.0 ; python_version >= "3.11" and python_version < "3.12"
60
+ typing-extensions==4.5.0 ; python_version >= "3.11" and python_version < "3.12"
61
+ tzdata==2023.3 ; python_version >= "3.11" and python_version < "3.12"
62
+ uc-micro-py==1.0.1 ; python_version >= "3.11" and python_version < "3.12"
63
+ urllib3==1.26.15 ; python_version >= "3.11" and python_version < "3.12"
64
+ uvicorn==0.21.1 ; python_version >= "3.11" and python_version < "3.12"
65
+ websockets==11.0.1 ; python_version >= "3.11" and python_version < "3.12"
66
+ yarl==1.8.2 ; python_version >= "3.11" and python_version < "3.12"