Spaces:
Running
Running
Zhu-FaceOnLive
commited on
Commit
β’
896ca03
1
Parent(s):
46938d1
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import base64
|
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
|
|
|
8 |
def image_to_base64(image):
|
9 |
buffered = BytesIO()
|
10 |
image.save(buffered, format="PNG")
|
@@ -14,6 +15,7 @@ def base64_to_image(base64_str):
|
|
14 |
return Image.open(BytesIO(base64.b64decode(base64_str + '=' * (-len(base64_str) % 4))))
|
15 |
|
16 |
def search_face(file):
|
|
|
17 |
url = os.environ.get("SERVER_URL")
|
18 |
|
19 |
try:
|
@@ -25,14 +27,15 @@ def search_face(file):
|
|
25 |
|
26 |
if r.text == "No matches":
|
27 |
gr.Info("No images found.")
|
28 |
-
return []
|
29 |
|
30 |
try:
|
31 |
res = r.json().get('img_array')
|
32 |
out_array = []
|
33 |
for item in res:
|
34 |
out_array.append((base64_to_image(item["image"]), item["url"] + "*********"))
|
35 |
-
|
|
|
36 |
except:
|
37 |
raise gr.Error("Try again.")
|
38 |
|
@@ -47,12 +50,13 @@ with gr.Blocks() as demo:
|
|
47 |
with gr.Row():
|
48 |
with gr.Column(scale=1):
|
49 |
image = gr.Image(type='filepath', height=480)
|
50 |
-
gr.Examples(['examples/1.jpg', 'examples/2.jpg'],
|
51 |
-
inputs=image)
|
52 |
search_face_button = gr.Button("Search Face")
|
53 |
with gr.Column(scale=2):
|
54 |
output = gr.Gallery(label="Found Images", columns=[4], object_fit="contain", height="auto")
|
55 |
|
|
|
|
|
|
|
56 |
search_face_button.click(search_face, inputs=[image], outputs=[output])
|
57 |
|
58 |
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/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
|
|
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
|
8 |
+
count = 0
|
9 |
def image_to_base64(image):
|
10 |
buffered = BytesIO()
|
11 |
image.save(buffered, format="PNG")
|
|
|
15 |
return Image.open(BytesIO(base64.b64decode(base64_str + '=' * (-len(base64_str) % 4))))
|
16 |
|
17 |
def search_face(file):
|
18 |
+
global count
|
19 |
url = os.environ.get("SERVER_URL")
|
20 |
|
21 |
try:
|
|
|
27 |
|
28 |
if r.text == "No matches":
|
29 |
gr.Info("No images found.")
|
30 |
+
return [], count
|
31 |
|
32 |
try:
|
33 |
res = r.json().get('img_array')
|
34 |
out_array = []
|
35 |
for item in res:
|
36 |
out_array.append((base64_to_image(item["image"]), item["url"] + "*********"))
|
37 |
+
count += 1
|
38 |
+
return out_array, count
|
39 |
except:
|
40 |
raise gr.Error("Try again.")
|
41 |
|
|
|
50 |
with gr.Row():
|
51 |
with gr.Column(scale=1):
|
52 |
image = gr.Image(type='filepath', height=480)
|
|
|
|
|
53 |
search_face_button = gr.Button("Search Face")
|
54 |
with gr.Column(scale=2):
|
55 |
output = gr.Gallery(label="Found Images", columns=[4], object_fit="contain", height="auto")
|
56 |
|
57 |
+
gr.Examples(['examples/1.jpg', 'examples/2.jpg'],
|
58 |
+
inputs=image, cache_examples="lazy", fn=search_face, outputs=[output])
|
59 |
+
|
60 |
search_face_button.click(search_face, inputs=[image], outputs=[output])
|
61 |
|
62 |
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/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Search-Online&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
|