Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mxrch
GitHub Repository: mxrch/GHunt
Path: blob/master/ghunt/helpers/ia.py
252 views
1
import os
2
3
from ghunt import globals as gb
4
from ghunt.apis.vision import VisionHttp
5
6
import httpx
7
8
from base64 import b64encode
9
import asyncio
10
11
12
async def detect_face(vision_api: VisionHttp, as_client: httpx.AsyncClient, image_url: str) -> None:
13
req = await as_client.get(image_url)
14
encoded_image = b64encode(req.content).decode()
15
16
are_faces_found = False
17
faces_results = None
18
19
for retry in range(5):
20
rate_limited, are_faces_found, faces_results = await vision_api.detect_faces(as_client, image_content=encoded_image)
21
if not rate_limited:
22
break
23
await asyncio.sleep(0.5)
24
else:
25
print("\n[-] Vision API keeps rate-limiting.")
26
exit(os.EX_UNAVAILABLE)
27
28
if are_faces_found:
29
if len(faces_results.face_annotations) > 1:
30
gb.rc.print(f"🎭 {len(faces_results.face_annotations)} faces detected !", style="italic")
31
else:
32
gb.rc.print(f"🎭 [+] Face detected !", style="italic bold")
33
else:
34
gb.rc.print(f"🎭 No face detected.", style="italic bright_black")
35
36
return faces_results
37