Spaces:
Sleeping
Sleeping
admin
commited on
Commit
·
9bd4611
1
Parent(s):
16dfbed
fix ordnum issue
Browse files- src/modules/app.py +20 -25
src/modules/app.py
CHANGED
@@ -14,25 +14,31 @@ For more information, see
|
|
14 |
- https://app.bitly.com/settings/api
|
15 |
'''
|
16 |
|
17 |
-
def calculate_layout(
|
18 |
layout = []
|
19 |
pos_x, pos_y = pos
|
20 |
-
pos_px, pos_py =
|
21 |
size_x, size_y = item_size
|
22 |
size_px, size_py = item_size
|
23 |
|
24 |
-
|
25 |
-
if pos_x + item_size[0] > page_size[0]: # Check for horizontal overflow
|
26 |
-
pos_x = 0
|
27 |
-
pos_y += item_size[1] + pos_py
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
pos_y = 0
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
with gr.Blocks() as demo:
|
38 |
gr.Markdown(description)
|
@@ -74,18 +80,7 @@ with gr.Blocks() as demo:
|
|
74 |
cm_img_input = gr.Files(file_types=img_formats, label='Insert common images')
|
75 |
idv_img_input = gr.Files(file_types=img_formats, label='Insert individual images')
|
76 |
|
77 |
-
headers = ['
|
78 |
-
|
79 |
-
@gr.render(inputs=[count_url, idv_img_input])
|
80 |
-
def update_df(*items): # TODO
|
81 |
-
items = 1 if items is None else items
|
82 |
-
image_count = math.prod(len(item) for item in items if item is not None)
|
83 |
-
|
84 |
-
if image_count is not None:
|
85 |
-
positions = calculate_layout(image_count)
|
86 |
-
df = pd.DataFrame(positions, columns=headers)
|
87 |
-
# df.insert(0, 'ImageId', range(1, image_count + 1))
|
88 |
-
return df
|
89 |
|
90 |
with gr.Column():
|
91 |
file_output = gr.File(label="Download ZIP")
|
@@ -114,7 +109,7 @@ with gr.Blocks() as demo:
|
|
114 |
gr.Examples(examples, inputs)
|
115 |
|
116 |
with gr.Row():
|
117 |
-
df = gr.Dataframe(headers=headers, label="Positions")
|
118 |
|
119 |
count_items = [count_url, idv_img_input]
|
120 |
txt_input.change(update_cnt, txt_input, count_url)
|
|
|
14 |
- https://app.bitly.com/settings/api
|
15 |
'''
|
16 |
|
17 |
+
def calculate_layout(item_size=(40, 40), pos=(280, 20), pos_p=(30, 67)):
|
18 |
layout = []
|
19 |
pos_x, pos_y = pos
|
20 |
+
pos_px, pos_py = pos_p
|
21 |
size_x, size_y = item_size
|
22 |
size_px, size_py = item_size
|
23 |
|
24 |
+
return layout, pos_x, pos_y, pos_px, pos_py, size_x, size_y, size_px, size_py
|
|
|
|
|
|
|
25 |
|
26 |
+
def update_df(*items):
|
27 |
+
items = [item for item in items if item is not None]
|
|
|
28 |
|
29 |
+
if len(items) >= 2 and all(items):
|
30 |
+
image_count = len(items[0]) * len(items[1])
|
31 |
+
else:
|
32 |
+
image_count = 1
|
33 |
+
|
34 |
+
if image_count:
|
35 |
+
layout, pos_x, pos_y, pos_px, pos_py, size_x, size_y, size_px, size_py = calculate_layout()
|
36 |
+
positions = [(pos_x, pos_y, pos_px, pos_py, size_x, size_y, size_px, size_py) for _ in range(image_count)]
|
37 |
+
|
38 |
+
df = pd.DataFrame(positions, columns=headers)
|
39 |
+
df.insert(0, 'ImageId', range(1, image_count + 1))
|
40 |
+
|
41 |
+
return df
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
gr.Markdown(description)
|
|
|
80 |
cm_img_input = gr.Files(file_types=img_formats, label='Insert common images')
|
81 |
idv_img_input = gr.Files(file_types=img_formats, label='Insert individual images')
|
82 |
|
83 |
+
headers = ['PosX', 'PosY', 'PosPx', 'PosPy', 'SizeX', 'SizeY', 'SizePx', 'SizePy']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
with gr.Column():
|
86 |
file_output = gr.File(label="Download ZIP")
|
|
|
109 |
gr.Examples(examples, inputs)
|
110 |
|
111 |
with gr.Row():
|
112 |
+
df = gr.Dataframe(headers=['ImageId'] + headers, label="Positions")
|
113 |
|
114 |
count_items = [count_url, idv_img_input]
|
115 |
txt_input.change(update_cnt, txt_input, count_url)
|