Spaces:
Sleeping
Sleeping
admin
commited on
Commit
·
3d1d388
1
Parent(s):
9ebdba1
auto url counter
Browse files- src/modules/app.py +16 -7
- src/modules/link.py +2 -3
src/modules/app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
-
import
|
2 |
-
import pandas as pd
|
3 |
import itertools
|
|
|
|
|
4 |
|
5 |
from link import UrlProcessor
|
6 |
# from main import TextProcessor
|
@@ -31,7 +32,6 @@ def calculate_positions(image_count, item_size=(20, 20), page_size=(91, 55), pad
|
|
31 |
print(positions)
|
32 |
return positions
|
33 |
|
34 |
-
|
35 |
with gr.Blocks() as demo:
|
36 |
gr.Markdown(description)
|
37 |
with gr.Row():
|
@@ -39,6 +39,11 @@ with gr.Blocks() as demo:
|
|
39 |
access_token = gr.Textbox(label="Access Token", placeholder="***")
|
40 |
api_url = gr.Textbox(label="API base URL", placeholder="https://")
|
41 |
txt_input = gr.TextArea(label="Enter Text with URLs")
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
with gr.Row():
|
44 |
shorten_checkbox = gr.Checkbox(label="Shorten URL", value=True)
|
@@ -51,16 +56,20 @@ with gr.Blocks() as demo:
|
|
51 |
idv_img_input = gr.Files(label='Insert individual images')
|
52 |
|
53 |
headers = ['ImageId', 'PosX', 'PosY', 'PosPx', 'PosPy']
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
58 |
df = pd.DataFrame(positions, columns=['PosX', 'PosY', 'PosPx', 'PosPy'])
|
59 |
df.insert(0, 'ImageId', range(1, image_count + 1))
|
60 |
return df
|
61 |
|
62 |
pos_df = gr.Dataframe(headers=headers, label="Positions")
|
63 |
|
|
|
|
|
64 |
cm_img_input.change(update_df, cm_img_input, pos_df)
|
65 |
idv_img_input.change(update_df, idv_img_input, pos_df)
|
66 |
|
|
|
1 |
+
import re
|
|
|
2 |
import itertools
|
3 |
+
import pandas as pd
|
4 |
+
import gradio as gr
|
5 |
|
6 |
from link import UrlProcessor
|
7 |
# from main import TextProcessor
|
|
|
32 |
print(positions)
|
33 |
return positions
|
34 |
|
|
|
35 |
with gr.Blocks() as demo:
|
36 |
gr.Markdown(description)
|
37 |
with gr.Row():
|
|
|
39 |
access_token = gr.Textbox(label="Access Token", placeholder="***")
|
40 |
api_url = gr.Textbox(label="API base URL", placeholder="https://")
|
41 |
txt_input = gr.TextArea(label="Enter Text with URLs")
|
42 |
+
count_url = gr.Dropdown(visible=False)
|
43 |
+
@gr.render(inputs=[txt_input])
|
44 |
+
def update_cnt(txt):
|
45 |
+
urls = re.findall(r'http[s]?://\S+', txt)
|
46 |
+
return urls
|
47 |
|
48 |
with gr.Row():
|
49 |
shorten_checkbox = gr.Checkbox(label="Shorten URL", value=True)
|
|
|
56 |
idv_img_input = gr.Files(label='Insert individual images')
|
57 |
|
58 |
headers = ['ImageId', 'PosX', 'PosY', 'PosPx', 'PosPy']
|
59 |
+
|
60 |
+
@gr.render(inputs=[count_url, cm_img_input, idv_img_input])
|
61 |
+
def update_df(*items):
|
62 |
+
image_count = sum(len(item) for item in items if item is not None)
|
63 |
+
if image_count is not None:
|
64 |
+
positions = calculate_positions(image_count)
|
65 |
df = pd.DataFrame(positions, columns=['PosX', 'PosY', 'PosPx', 'PosPy'])
|
66 |
df.insert(0, 'ImageId', range(1, image_count + 1))
|
67 |
return df
|
68 |
|
69 |
pos_df = gr.Dataframe(headers=headers, label="Positions")
|
70 |
|
71 |
+
txt_input.change(update_cnt, txt_input, count_url)
|
72 |
+
count_url.change(update_df, count_url, pos_df)
|
73 |
cm_img_input.change(update_df, cm_img_input, pos_df)
|
74 |
idv_img_input.change(update_df, idv_img_input, pos_df)
|
75 |
|
src/modules/link.py
CHANGED
@@ -100,6 +100,8 @@ class UrlProcessor:
|
|
100 |
index_path = 'index.html'
|
101 |
css_path = 'style.css'
|
102 |
|
|
|
|
|
103 |
for idx, url in enumerate(urls):
|
104 |
shorten_url, shorten_response_json = None, None
|
105 |
try:
|
@@ -161,9 +163,6 @@ class UrlProcessor:
|
|
161 |
|
162 |
processor = ImageProcessor()
|
163 |
layer = processor.create_layer()
|
164 |
-
# for qr in qr_svgs:
|
165 |
-
# with open(qr, "rb") as image_file:
|
166 |
-
# encoded_string = base64.b64encode(image_file.read()).decode()
|
167 |
|
168 |
os.makedirs(f'{tmpd}/img/cards', exist_ok=True)
|
169 |
|
|
|
100 |
index_path = 'index.html'
|
101 |
css_path = 'style.css'
|
102 |
|
103 |
+
if urls is not None:
|
104 |
+
urls = urls if urls is not None else []
|
105 |
for idx, url in enumerate(urls):
|
106 |
shorten_url, shorten_response_json = None, None
|
107 |
try:
|
|
|
163 |
|
164 |
processor = ImageProcessor()
|
165 |
layer = processor.create_layer()
|
|
|
|
|
|
|
166 |
|
167 |
os.makedirs(f'{tmpd}/img/cards', exist_ok=True)
|
168 |
|