Spaces:
Build error
Build error
Mya-Mya
commited on
Commit
·
17725c1
1
Parent(s):
d42d8ff
First Commit
Browse files- .gitignore +1 -0
- app.py +8 -0
- backend.py +8 -0
- dummysengafiller.py +6 -0
- frontend.py +48 -0
- jgdildsengafiller.py +21 -0
- model1.h5 +3 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__/
|
app.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from backend import SengaFiller
|
2 |
+
import frontend
|
3 |
+
|
4 |
+
from jgdildsengafiller import JGDILDSengaFiller
|
5 |
+
|
6 |
+
frontend.init(
|
7 |
+
sengafiller=JGDILDSengaFiller()
|
8 |
+
)
|
backend.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from abc import ABC,abstractmethod
|
2 |
+
from numpy import ndarray
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
class SengaFiller(ABC):
|
6 |
+
@abstractmethod
|
7 |
+
def run(image:Image.Image)->ndarray:
|
8 |
+
pass
|
dummysengafiller.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from backend import SengaFiller
|
2 |
+
from numpy import ndarray,asarray
|
3 |
+
from PIL import Image
|
4 |
+
class DummySengaFiller(SengaFiller):
|
5 |
+
def run(self,image: Image.Image) -> ndarray:
|
6 |
+
return asarray(image)
|
frontend.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from backend import SengaFiller
|
2 |
+
def init(sengafiller:SengaFiller):
|
3 |
+
from gradio import Blocks, Markdown, Image, Row, Button, Box
|
4 |
+
|
5 |
+
with Blocks() as app:
|
6 |
+
|
7 |
+
# Prepare Components
|
8 |
+
Markdown(
|
9 |
+
"""# SengaFiller
|
10 |
+
Connects the lines you draw so that you can fill your drawing correctly.
|
11 |
+
"""
|
12 |
+
)
|
13 |
+
with Box().style(rounded=True, margin=True):
|
14 |
+
input_image = Image(label="input",image_mode="L",type="pil")
|
15 |
+
with Box().style(border=False):
|
16 |
+
with Row().style(equal_height=True):
|
17 |
+
submit_button = Button("RUN", variant="primary").style(
|
18 |
+
full_width=True, rounded=(True, False, False, True)
|
19 |
+
)
|
20 |
+
clear_button = Button("CLEAR").style(
|
21 |
+
full_width=True, rounded=(False, True, True, False)
|
22 |
+
)
|
23 |
+
output_image = Image(label="output")
|
24 |
+
Markdown(
|
25 |
+
"""
|
26 |
+
### Credit
|
27 |
+
The model `model1.h5` is licensed under a CC-BY-NC-SA 4.0 international license, created by [hepesu](https://github.com/hepesu) and available on [Release Page of LineCloser Repo](https://github.com/hepesu/LineCloser/releases)
|
28 |
+
"""
|
29 |
+
)
|
30 |
+
|
31 |
+
# Event Handlers
|
32 |
+
def on_submit_button_click(input_image_data):
|
33 |
+
return sengafiller.run(input_image_data)
|
34 |
+
def on_clear_button_click():
|
35 |
+
return None,None
|
36 |
+
|
37 |
+
# Connect Components
|
38 |
+
submit_button.click(
|
39 |
+
fn=on_submit_button_click, inputs=[input_image], outputs=[output_image]
|
40 |
+
)
|
41 |
+
clear_button.click(
|
42 |
+
fn=on_clear_button_click,inputs=[],outputs=[input_image,output_image]
|
43 |
+
)
|
44 |
+
app.launch()
|
45 |
+
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
init()
|
jgdildsengafiller.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from backend import SengaFiller
|
2 |
+
from numpy import ndarray, cast, int8, ones
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
|
6 |
+
class JGDILDSengaFiller(SengaFiller):
|
7 |
+
def __init__(self) -> None:
|
8 |
+
super().__init__()
|
9 |
+
from tensorflow import keras
|
10 |
+
|
11 |
+
self.model = keras.models.load_model("./model1.h5")
|
12 |
+
|
13 |
+
def run(self, image_pil: Image.Image) -> ndarray:
|
14 |
+
input_width, input_height = image_pil.size
|
15 |
+
image_mono_pil = image_pil.point(lambda x: int(x > 200), mode="L")
|
16 |
+
image_numpy = ones((input_height, input_width)) * image_mono_pil
|
17 |
+
x = image_numpy.reshape((1, input_height, input_width, 1))
|
18 |
+
y = self.model(x)
|
19 |
+
output_height, output_width = y.shape[1:3]
|
20 |
+
output_image = y.numpy().reshape(output_height, output_width)
|
21 |
+
return output_image
|
model1.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c7f60bed0cfff29523a9fedc9b8b99460f313da39ce446a1d3fb7992ded6e29d
|
3 |
+
size 66259544
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
tensorflow
|