forked from ZennoLab/capmonstercloud-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecognitionCIT.py
More file actions
42 lines (37 loc) · 1.69 KB
/
Copy pathrecognitionCIT.py
File metadata and controls
42 lines (37 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import time
import asyncio
import base64
from capmonstercloudclient.requests import RecognitionComplexImageTaskRequest
from capmonstercloudclient import ClientOptions, CapMonsterClient
async def solve_captcha_sync(num_requests):
return [await cap_monster_client.solve_captcha(oocl_request) for _ in range(num_requests)]
async def solve_captcha_async(num_requests):
tasks = [asyncio.create_task(cap_monster_client.solve_captcha(oocl_request))
for _ in range(num_requests)]
return await asyncio.gather(*tasks, return_exceptions=True)
if __name__ == '__main__':
key = os.getenv('API_KEY')
client_options = ClientOptions(api_key=key)
cap_monster_client = CapMonsterClient(options=client_options)
with open("/path/to/img/0_2.png", 'rb') as f:
bg = base64.b64encode(f.read()).decode("utf-8")
with open("/path/to/img/0_0.png", 'rb') as f:
ring = base64.b64encode(f.read()).decode("utf-8")
with open("/path/to/img/0_1.png", 'rb') as f:
circle = base64.b64encode(f.read()).decode("utf-8")
oocl_request = RecognitionComplexImageTaskRequest(
metadata={"Task": "oocl_rotate_double_new"},
imagesBase64=[bg, ring, circle]
)
nums = 3
# Sync test
sync_start = time.time()
sync_responses = asyncio.run(solve_captcha_sync(nums))
print(f'average execution time sync {1/((time.time()-sync_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {sync_responses[0]}')
# Async test
async_start = time.time()
async_responses = asyncio.run(solve_captcha_async(nums))
print(f'average execution time async {1/((time.time()-async_start)/nums):0.2f} ' \
f'resp/sec\nsolution: {async_responses[0]}')