Neural Network Model for solving captchas in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
пре 6 месеци
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from fastapi import FastAPI, HTTPException
  2. from pydantic import BaseModel
  3. from typing import Optional
  4. from fastapi.middleware.cors import CORSMiddleware
  5. import threading
  6. # Suponha que quebrar_captcha_base64 está definido em outro módulo ou arquivo
  7. from solve_captcha import quebrar_captcha_base64
  8. app = FastAPI()
  9. app.add_middleware(
  10. CORSMiddleware,
  11. allow_origins=["*"], # Ajuste conforme necessário
  12. allow_credentials=True,
  13. allow_methods=["*"], # Ajuste conforme necessário
  14. allow_headers=["*"],
  15. )
  16. # Criando um bloqueio para gerenciamento de concorrência
  17. lock = threading.Lock()
  18. class CaptchaRequest(BaseModel):
  19. captchafile: str
  20. authtoken: str
  21. @app.post("/solve_captcha")
  22. async def solve_captcha(request: CaptchaRequest):
  23. expected_token = "j7MgdTy4LX05RpE1XY0ykLTexu9LuOE4zg5AEMNymL6LAgCUNN8JGjM5wu26FDGV4j0Xz3km8ra51c3ihToa3fj48XpcsWr45g043bLVQA1sTBkJP4j823DNX67mbjqNR8p117sU580153Id0IavORjkCXRP"
  24. if request.authtoken != expected_token:
  25. # Se o token não corresponder, retorne erro 401 Unauthorized
  26. raise HTTPException(status_code=401, detail="Unauthorized")
  27. if not request.captchafile:
  28. raise HTTPException(status_code=400, detail="captchafile is required")
  29. try:
  30. lock.acquire()
  31. resultado_captcha = quebrar_captcha_base64(request.captchafile)
  32. lock.release()
  33. return {"captcha": "", "text": resultado_captcha, "is_correct": True, "status": 200}
  34. except Exception as e:
  35. lock.release()
  36. raise HTTPException(status_code=500, detail=str(e))