forked from QIN2DIM/hcaptcha-challenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
124 lines (101 loc) · 4.22 KB
/
main.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
# Time : 2022/2/15 17:40
# Author : QIN2DIM
# Github : https://github.com/QIN2DIM
# Description: 🚀 Yo Challenger!
import typing
import warnings
from fire import Fire
from examples import demo_selenium, demo_challenge, demo_install, demo_classify
from examples.motion import app, motion
from examples.settings import config
demo_install.do()
warnings.filterwarnings("ignore", category=DeprecationWarning)
class Scaffold:
"""System scaffolding Top-level interface commands"""
CHALLENGE_LANGUAGE = "en"
def __init__(self, lang: typing.Optional[str] = None):
if lang is not None:
Scaffold.CHALLENGE_LANGUAGE = lang
self.challenge = self.demo
self.run = self.demo
@staticmethod
def install(model: typing.Optional[str] = None, upgrade: typing.Optional[bool] = False):
"""Download Project Dependencies and upgrade all pluggable ONNX model"""
demo_install.do(yolo_onnx_prefix=model, upgrade=upgrade)
@staticmethod
def test():
"""Test the Challenger drive for fitment"""
demo_challenge.test()
@staticmethod
def tracker():
app.run(debug=True, access_log=False)
@staticmethod
def motion():
motion.train_motion("http://127.0.0.1:8000", config.dir_database)
@staticmethod
def demo(
silence: typing.Optional[bool] = False,
model: typing.Optional[str] = None,
target: typing.Optional[str] = None,
sitekey: typing.Optional[str] = None,
screenshot: typing.Optional[bool] = False,
repeat: typing.Optional[int] = 5,
slowdown: typing.Optional[bool] = True,
):
"""
Dueling with hCAPTCHA challenge using YOLOv5.
Usage: python main.py demo [flags]
——————————————————————————————————————————————————————————————————
or: python main.py demo --model=yolov5n6
or: python main.py demo --target=discord
or: python main.py demo --lang=en
or: python main.py demo --sitekey=[UUID]
or: pythoon main.py demo --slowdown=False
——————————————————————————————————————————————————————————————————
:param slowdown: Add a short sleep so that the user can see the prediction results of the model
:param repeat: Default 5. Number of times to repeat the presentation.
:param screenshot: Default False. Save screenshot of the challenge result.
PATH: database/temp_cache/captcha_screenshot/
FILENAME: ChallengeLabelName.png
:param sitekey: Default None. customize the challenge theme via sitekey
:param silence: Default False. Whether to startup headless browser.
:param model: Default "yolov5s6". Select the YOLO model to handle specific challenges.
within [yolov5n6 yolov5s6 yolov5m6 yolov6n yolov6t yolov6s]
:param target: Default None. Designate `Challenge Source`. See the global value SITE_KEYS.
:return:
"""
# Generate challenge topics
if config.SITE_KEYS.get(target):
sample_site = config.HCAPTCHA_DEMO_API.format(config.SITE_KEYS[target])
else:
sample_site = config.HCAPTCHA_DEMO_SITES[0]
if sitekey is not None:
sample_site = config.HCAPTCHA_DEMO_API.format(sitekey.strip())
demo_challenge.run(
sample_site,
lang=Scaffold.CHALLENGE_LANGUAGE,
silence=silence,
onnx_prefix=model,
screenshot=screenshot,
repeat=repeat,
slowdown=slowdown,
)
@staticmethod
def demo_bytedance():
"""
signup hcaptcha dashboard
Usage: python main.py demo-bytedance
:return:
"""
demo_selenium.bytedance()
@staticmethod
def demo_classify():
"""
BinaryClassification Task
Usage: python main.py demo-classify
:return:
"""
demo_classify.bytedance()
if __name__ == "__main__":
Fire(Scaffold)