Download server.py from karakara73/rcs: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/karakara73/rcs/resolve/main/server.py
- Command line
-
hf download hf://karakara73/rcs/server.py
-
curl -L -o server.py https://huggingface.co/karakara73/rcs/resolve/main/server.py
2.59 kB
| import threading | |
| import time | |
| import queue | |
| import uuid | |
| from flask import Flask, jsonify, request | |
| from api import RecaptchaBypass | |
| app = Flask(__name__) | |
| job_queue = queue.Queue() | |
| job_results = {} | |
| MAX_WORKERS = 1 | |
| import traceback | |
| def worker(): | |
| """Process jobs from queue one at a time""" | |
| while True: | |
| job_id, url, use_proxy, use_agent, debug, headless = job_queue.get() | |
| try: | |
| instance = RecaptchaBypass(debug=debug, use_proxy=use_proxy, use_agent=use_agent, headless=headless) | |
| result = instance.get_token(url) | |
| job_results[job_id] = result | |
| except Exception as e: | |
| tb = traceback.format_exc() | |
| # store full traceback for debugging and log it | |
| job_results[job_id] = {'success': False, 'error': str(e), 'traceback': tb} | |
| print(tb) | |
| finally: | |
| # Ensure the queue task is marked done even if an error occurs | |
| try: | |
| job_queue.task_done() | |
| except Exception: | |
| pass | |
| # Start worker threads | |
| for _ in range(MAX_WORKERS): | |
| t = threading.Thread(target=worker, daemon=True) | |
| t.start() | |
| def solve_recaptcha(): | |
| data = request.get_json() | |
| if not data or 'url' not in data: | |
| return jsonify({'success': False, 'error': 'Missing "url" parameter'}), 400 | |
| url = data['url'] | |
| use_proxy = data.get('proxy', False) | |
| use_agent = data.get('agent', False) | |
| debug = data.get('debug', False) | |
| # Default to headless mode on servers without a display. Clients can override. | |
| headless = data.get('headless', True) | |
| job_id = str(uuid.uuid4()) | |
| job_queue.put((job_id, url, use_proxy, use_agent, debug, headless)) | |
| job_results[job_id] = {'status': 'queued'} | |
| return jsonify({'job_id': job_id, 'status': 'queued', 'check_url': f'/status/{job_id}'}), 202 | |
| def check_status(job_id): | |
| result = job_results.get(job_id) | |
| if not result: | |
| return jsonify({'success': False, 'error': 'Job not found'}), 404 | |
| if 'status' in result and result['status'] == 'queued': | |
| return jsonify({'status': 'processing'}) | |
| return jsonify(result) | |
| def health(): | |
| return jsonify({'status': 'ok', 'queue_size': job_queue.qsize()}) | |
| def list_jobs(): | |
| jobs = {jid: status for jid, status in job_results.items()} | |
| return jsonify(jobs) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=8002, threaded=True) | |