Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ from PIL import Image
|
|
7 |
import imagehash
|
8 |
import requests
|
9 |
|
|
|
|
|
10 |
from time import sleep
|
11 |
sleep_time = 0.5
|
12 |
|
@@ -99,6 +101,17 @@ def search(prompt, search_name, im, func_name):
|
|
99 |
return t2_list
|
100 |
#return list(map(lambda x: x["name"], t2_list))
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
with gr.Blocks(css="custom.css") as demo:
|
104 |
title = gr.HTML(
|
@@ -119,6 +132,11 @@ with gr.Blocks(css="custom.css") as demo:
|
|
119 |
text_button = gr.Button("Retrieve Images", elem_id="run_button")
|
120 |
i = gr.Image(elem_id="result-image", label = "Image upload or selected", height = 768 - 256 - 32)
|
121 |
|
|
|
|
|
|
|
|
|
|
|
122 |
with gr.Column():
|
123 |
title = gr.Markdown(
|
124 |
value="### Click on a Image in the gallery to select it, and the grid order will change",
|
@@ -128,10 +146,11 @@ with gr.Blocks(css="custom.css") as demo:
|
|
128 |
order_func_name = gr.Radio(choices=hash_func_name,
|
129 |
value=hash_func_name[0], label="Order by", elem_id="order_radio")
|
130 |
|
131 |
-
outputs = gr.Gallery(lable='Output gallery', elem_id="gallery",).style(grid=5,height=768
|
132 |
allow_preview=False, label = "retrieve Images")
|
133 |
#gr.Dataframe(label='prompts for corresponding images')]
|
134 |
|
|
|
135 |
with gr.Row():
|
136 |
gr.Examples(
|
137 |
[
|
@@ -170,6 +189,8 @@ with gr.Blocks(css="custom.css") as demo:
|
|
170 |
#text_button.click(enterpix, inputs=inputs, outputs=outputs)
|
171 |
text_button.click(search, inputs=[inputs, search_func_name, i, order_func_name], outputs=outputs)
|
172 |
|
173 |
-
|
|
|
|
|
174 |
|
175 |
demo.launch("0.0.0.0")
|
|
|
7 |
import imagehash
|
8 |
import requests
|
9 |
|
10 |
+
from zipfile import ZipFile
|
11 |
+
|
12 |
from time import sleep
|
13 |
sleep_time = 0.5
|
14 |
|
|
|
101 |
return t2_list
|
102 |
#return list(map(lambda x: x["name"], t2_list))
|
103 |
|
104 |
+
def zip_ims(g):
|
105 |
+
from uuid import uuid1
|
106 |
+
if g is None:
|
107 |
+
return None
|
108 |
+
l = list(map(lambda x: x["name"], g))
|
109 |
+
zip_file_name ="tmp.zip"
|
110 |
+
with ZipFile(zip_file_name ,"w") as zipObj:
|
111 |
+
for ele in l:
|
112 |
+
zipObj.write(ele, "{}.png".format(uuid1()))
|
113 |
+
#zipObj.write(file2.name, "file2")
|
114 |
+
return zip_file_name
|
115 |
|
116 |
with gr.Blocks(css="custom.css") as demo:
|
117 |
title = gr.HTML(
|
|
|
132 |
text_button = gr.Button("Retrieve Images", elem_id="run_button")
|
133 |
i = gr.Image(elem_id="result-image", label = "Image upload or selected", height = 768 - 256 - 32)
|
134 |
|
135 |
+
with gr.Row():
|
136 |
+
with gr.Tab(label = "Download"):
|
137 |
+
zip_button = gr.Button("Zip Images to Download", elem_id="zip_button")
|
138 |
+
downloads = gr.File(label = "Image zipped", elem_id = "zip_file")
|
139 |
+
|
140 |
with gr.Column():
|
141 |
title = gr.Markdown(
|
142 |
value="### Click on a Image in the gallery to select it, and the grid order will change",
|
|
|
146 |
order_func_name = gr.Radio(choices=hash_func_name,
|
147 |
value=hash_func_name[0], label="Order by", elem_id="order_radio")
|
148 |
|
149 |
+
outputs = gr.Gallery(lable='Output gallery', elem_id="gallery",).style(grid=5,height=768 + 64 + 32,
|
150 |
allow_preview=False, label = "retrieve Images")
|
151 |
#gr.Dataframe(label='prompts for corresponding images')]
|
152 |
|
153 |
+
|
154 |
with gr.Row():
|
155 |
gr.Examples(
|
156 |
[
|
|
|
189 |
#text_button.click(enterpix, inputs=inputs, outputs=outputs)
|
190 |
text_button.click(search, inputs=[inputs, search_func_name, i, order_func_name], outputs=outputs)
|
191 |
|
192 |
+
zip_button.click(
|
193 |
+
zip_ims, inputs = outputs, outputs=downloads
|
194 |
+
)
|
195 |
|
196 |
demo.launch("0.0.0.0")
|