Commit
·
86f7d47
1
Parent(s):
6a8a06c
WIP
Browse files
app.py
CHANGED
|
@@ -5,8 +5,40 @@ import base64
|
|
| 5 |
from io import BytesIO
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
with gr.Blocks() as demo:
|
| 12 |
gr.Markdown(
|
|
|
|
| 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")
|
| 12 |
+
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 13 |
+
|
| 14 |
+
def base64_to_image(base64_str):
|
| 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:
|
| 22 |
+
image = Image.open(file)
|
| 23 |
+
image_base64 = image_to_base64(image)
|
| 24 |
+
r = requests.post(url=url, json={"token": os.environ.get("ACCESS_TOKEN"), "type": "novip", "image": image_base64})
|
| 25 |
+
except:
|
| 26 |
+
raise gr.Error("Please select image file!")
|
| 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 |
+
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.Markdown(
|