Spaces:
Sleeping
Sleeping
hysts
commited on
Commit
·
1aa3766
1
Parent(s):
7406a45
Add files
Browse files- .gitattributes +1 -0
- app.py +60 -0
- images/pexels-pixabay-45170.jpg +3 -0
- requirements.txt +2 -0
.gitattributes
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
2 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
3 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
4 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pathlib
|
2 |
+
|
3 |
+
import cv2
|
4 |
+
import gradio as gr
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
MAX_W, MAX_H = 600, 400
|
8 |
+
|
9 |
+
|
10 |
+
def update_input_image(image: np.ndarray):
|
11 |
+
if image is None:
|
12 |
+
return gr.Image.update(value=None)
|
13 |
+
|
14 |
+
h, w = image.shape[:2]
|
15 |
+
scale = min(MAX_W / w, MAX_H / h)
|
16 |
+
if scale < 1:
|
17 |
+
image = cv2.resize(image, None, fx=scale, fy=scale)
|
18 |
+
return gr.Image.update(value=image)
|
19 |
+
|
20 |
+
|
21 |
+
def set_example_image(example):
|
22 |
+
return [
|
23 |
+
gr.Image.update(value=example[0]),
|
24 |
+
gr.Image.update(value=example[0])
|
25 |
+
]
|
26 |
+
|
27 |
+
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column():
|
31 |
+
input_image1 = gr.Image(label='Input',
|
32 |
+
type='numpy',
|
33 |
+
shape=(MAX_W, MAX_H))
|
34 |
+
with gr.Column():
|
35 |
+
output_image1 = gr.Image(label='Output')
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
with gr.Column():
|
39 |
+
input_image2 = gr.Image(label='Input', type='numpy')
|
40 |
+
with gr.Column():
|
41 |
+
output_image2 = gr.Image(label='Output')
|
42 |
+
|
43 |
+
button = gr.Button('Run')
|
44 |
+
|
45 |
+
with gr.Row():
|
46 |
+
paths = sorted(pathlib.Path('images').rglob('*.jpg'))
|
47 |
+
examples = gr.Dataset(components=[input_image1, input_image2],
|
48 |
+
samples=[[path.as_posix(),
|
49 |
+
path.as_posix()] for path in paths])
|
50 |
+
|
51 |
+
input_image2.change(fn=update_input_image,
|
52 |
+
inputs=input_image2,
|
53 |
+
outputs=input_image2)
|
54 |
+
button.click(fn=lambda x: x, inputs=input_image1, outputs=output_image1)
|
55 |
+
button.click(fn=lambda x: x, inputs=input_image2, outputs=output_image2)
|
56 |
+
examples.click(fn=set_example_image,
|
57 |
+
inputs=[examples],
|
58 |
+
outputs=[input_image1, input_image2])
|
59 |
+
|
60 |
+
demo.launch()
|
images/pexels-pixabay-45170.jpg
ADDED
![]() |
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
opencv-python-headless
|