zhou12189108 commited on
Commit
11a27a1
·
1 Parent(s): 29d2b86

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -0
  2. api.py +12 -2
  3. get_all_model.py +28 -0
Dockerfile CHANGED
@@ -40,6 +40,7 @@ RUN playwright install firefox --with-deps
40
  USER foxer
41
  RUN playwright install firefox
42
  COPY hcaptcha_solver.py .
 
43
  COPY api.py .
44
  EXPOSE 7860
45
 
 
40
  USER foxer
41
  RUN playwright install firefox
42
  COPY hcaptcha_solver.py .
43
+ COPY get_all_model.py .
44
  COPY api.py .
45
  EXPOSE 7860
46
 
api.py CHANGED
@@ -1,8 +1,11 @@
1
  import os
2
  import asyncio
 
 
3
  from flask import Flask, jsonify, request, logging as flog
4
  from flask_limiter.util import get_remote_address
5
  import hcaptcha_solver
 
6
 
7
  app = Flask(__name__)
8
 
@@ -36,6 +39,12 @@ def check_request(required_data, data):
36
  return True
37
 
38
 
 
 
 
 
 
 
39
  @app.errorhandler(429)
40
  def rate_limit_exceeded(e):
41
  print(get_remote_address())
@@ -73,5 +82,6 @@ def solver_captcha():
73
  return jsonify(msg="Unauthorized Request"), 403
74
  return asyncio.run(hcaptcha_solver.bytedance(data["host"], data["site_key"]))
75
 
76
-
77
- app.run(host="0.0.0.0", port=7860)
 
 
1
  import os
2
  import asyncio
3
+ import time
4
+ import multiprocessing
5
  from flask import Flask, jsonify, request, logging as flog
6
  from flask_limiter.util import get_remote_address
7
  import hcaptcha_solver
8
+ import get_all_model
9
 
10
  app = Flask(__name__)
11
 
 
39
  return True
40
 
41
 
42
+ def update_models():
43
+ while True:
44
+ get_all_model.download_all()
45
+ time.sleep(30 * 60)
46
+
47
+
48
  @app.errorhandler(429)
49
  def rate_limit_exceeded(e):
50
  print(get_remote_address())
 
82
  return jsonify(msg="Unauthorized Request"), 403
83
  return asyncio.run(hcaptcha_solver.bytedance(data["host"], data["site_key"]))
84
 
85
+ process = multiprocessing.Process(target=update_models)
86
+ process.start()
87
+ app.run(host="0.0.0.0", port=7860)
get_all_model.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+ import requests
4
+ import re
5
+
6
+ username = "QIN2DIM"
7
+ repo = "hcaptcha-challenger"
8
+
9
+ url = f"https://api.github.com/repos/{username}/{repo}/releases"
10
+ models_dir = "/usr/local/lib/python3.11/lib/site-packages/hcaptcha_challenger/onnx/models/"
11
+
12
+
13
+ def download_all():
14
+ session = requests.session()
15
+ response = session.get(url)
16
+ data = response.json()
17
+ os.makedirs(models_dir, exist_ok=True)
18
+ for i in data:
19
+ for j in i['assets']:
20
+ asset_url = j['browser_download_url']
21
+ asset_name = re.sub('.*/', '', asset_url)
22
+ print(f'Downloading {asset_name}')
23
+ models_path = models_dir + asset_name
24
+ if os.path.exists(models_path):
25
+ continue
26
+ r = session.get(asset_url, stream=True)
27
+ with open(models_path, 'wb') as f:
28
+ f.write(r.content)