Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ from io import BytesIO
|
|
6 |
from PIL import Image
|
7 |
import hashlib
|
8 |
import concurrent.futures
|
|
|
|
|
9 |
|
10 |
# Constants
|
11 |
FREE_URL = os.environ.get("SERVER_URL_FREE")
|
@@ -135,11 +137,35 @@ def search_face(file, token=None):
|
|
135 |
soc_res = process_response2(response2) if response2 else None
|
136 |
return process_response(response1, soc_res, url, token)
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
custom_css = """
|
139 |
caption.caption {
|
140 |
user-select: text;
|
141 |
cursor: text;
|
142 |
}
|
|
|
|
|
|
|
|
|
143 |
"""
|
144 |
|
145 |
js = """
|
@@ -181,6 +207,7 @@ head = """
|
|
181 |
</script>
|
182 |
"""
|
183 |
|
|
|
184 |
with gr.Blocks(css=custom_css, head=head) as demo:
|
185 |
gr.Markdown(
|
186 |
"""
|
@@ -196,12 +223,18 @@ with gr.Blocks(css=custom_css, head=head) as demo:
|
|
196 |
gr.HTML("<a href='https://faceonlive.pocketsflow.com/checkout?productId=676c15b1971244a587ca07cb' target='_blank'>Get Premium Token: Deep Search Including Social Media & Full URL Reveal</a>")
|
197 |
gr.HTML("<a href='https://faceonlive.pocketsflow.com/checkout?productId=676d7e7597f8b3b699f84820' target='_blank'>Protect Your Privacy β Start Your Takedown Now</a>")
|
198 |
search_face_button = gr.Button("Search Face")
|
|
|
|
|
199 |
with gr.Column(scale=2):
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
203 |
|
204 |
search_face_button.click(search_face, inputs=[image, token], outputs=[output], api_name=False)
|
|
|
205 |
|
206 |
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online"><img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
|
207 |
html = gr.HTML()
|
|
|
6 |
from PIL import Image
|
7 |
import hashlib
|
8 |
import concurrent.futures
|
9 |
+
import zipfile
|
10 |
+
import tempfile
|
11 |
|
12 |
# Constants
|
13 |
FREE_URL = os.environ.get("SERVER_URL_FREE")
|
|
|
137 |
soc_res = process_response2(response2) if response2 else None
|
138 |
return process_response(response1, soc_res, url, token)
|
139 |
|
140 |
+
def export_images(items):
|
141 |
+
if not items:
|
142 |
+
return None
|
143 |
+
# Create a zip file in memory
|
144 |
+
zip_buffer = BytesIO()
|
145 |
+
with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
|
146 |
+
url_text = ""
|
147 |
+
for i, item in enumerate(items):
|
148 |
+
with open(item[0], 'rb') as img_file:
|
149 |
+
zip_file.writestr(f'image_{i}.jpg', img_file.read())
|
150 |
+
url_text += f"image_{i}.jpg: {item[1]}\n"
|
151 |
+
zip_file.writestr("urls.txt", url_text)
|
152 |
+
zip_buffer.seek(0)
|
153 |
+
|
154 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".zip") as temp_file:
|
155 |
+
temp_file.write(zip_buffer.getvalue())
|
156 |
+
temp_file_path = temp_file.name
|
157 |
+
|
158 |
+
return temp_file_path
|
159 |
+
|
160 |
custom_css = """
|
161 |
caption.caption {
|
162 |
user-select: text;
|
163 |
cursor: text;
|
164 |
}
|
165 |
+
|
166 |
+
div#component-16 {
|
167 |
+
max-height: 63.39px;
|
168 |
+
}
|
169 |
"""
|
170 |
|
171 |
js = """
|
|
|
207 |
</script>
|
208 |
"""
|
209 |
|
210 |
+
output = gr.Gallery(label="Found Images", columns=[4], object_fit="contain", height="auto")
|
211 |
with gr.Blocks(css=custom_css, head=head) as demo:
|
212 |
gr.Markdown(
|
213 |
"""
|
|
|
223 |
gr.HTML("<a href='https://faceonlive.pocketsflow.com/checkout?productId=676c15b1971244a587ca07cb' target='_blank'>Get Premium Token: Deep Search Including Social Media & Full URL Reveal</a>")
|
224 |
gr.HTML("<a href='https://faceonlive.pocketsflow.com/checkout?productId=676d7e7597f8b3b699f84820' target='_blank'>Protect Your Privacy β Start Your Takedown Now</a>")
|
225 |
search_face_button = gr.Button("Search Face")
|
226 |
+
gr.Examples(['examples/1.jpg', 'examples/2.jpg'], inputs=image, cache_examples=True, cache_mode='lazy', fn=search_face, outputs=[output])
|
227 |
+
|
228 |
with gr.Column(scale=2):
|
229 |
+
gr.Markdown("> ### **β οΈ Reminder:** Export images before refreshing the page by clicking the 'Export Images' button.")
|
230 |
+
output.render()
|
231 |
+
with gr.Row():
|
232 |
+
export_button = gr.Button("Export Images")
|
233 |
+
export_file = gr.File(label="Download")
|
234 |
+
|
235 |
|
236 |
search_face_button.click(search_face, inputs=[image, token], outputs=[output], api_name=False)
|
237 |
+
export_button.click(export_images, inputs=[output], outputs=export_file, api_name=False)
|
238 |
|
239 |
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online"><img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
|
240 |
html = gr.HTML()
|