imperialwool commited on
Commit
9fda7ee
·
1 Parent(s): f3d4672

Delete routes/aminoOSRapi

Browse files
routes/aminoOSRapi/__init__.py DELETED
@@ -1 +0,0 @@
1
- from .main import apipredict
 
 
routes/aminoOSRapi/__pycache__/utils.cpython-311.pyc DELETED
Binary file (4.2 kB)
 
routes/aminoOSRapi/main.py DELETED
@@ -1,88 +0,0 @@
1
- import random
2
- import string
3
- import requests
4
- import pytesseract
5
- from PIL import Image, ImageEnhance
6
-
7
- def apipredict(request):
8
- try:
9
- if request.method == 'POST': url = request.form['url']
10
- else: url = request.args['url']
11
- if url.strip() in ['', None]:
12
- raise Exception()
13
- except: return {"status": "error", "details": { "error_code": 101, "error_details": "No link provided" }}
14
-
15
- WALK_Y = 33
16
-
17
- WHITE_RGB = (255, 255, 255)
18
-
19
- def replaceColor(image: Image, forReplace: tuple, newColor: tuple):
20
- for y in range(image.size[1]):
21
- for x in range(image.size[0]):
22
- if pix[x, y] == forReplace:
23
- image.putpixel((x, y), newColor)
24
-
25
- name = ''.join([random.choice(string.ascii_lowercase) for _ in range(random.randint(6,12))])
26
- response = requests.get(url)
27
- with open(f'{name}.png', 'wb') as fp:
28
- fp.write(response.content)
29
-
30
- image = Image.open(f'{name}.png')
31
-
32
- pix = image.load()
33
-
34
- garbageColor = image.getpixel((0, 0))
35
-
36
- replaceColor(image, garbageColor, WHITE_RGB)
37
-
38
- colors = []
39
-
40
- for i in range(249):
41
- pixel = image.getpixel((i, WALK_Y))
42
- if pixel != WHITE_RGB:
43
- colors.append(pixel)
44
-
45
- captchaLettersColor = max(set(colors), key = colors.count)
46
-
47
- for y in range(image.size[1]):
48
- for x in range(image.size[0]):
49
- if pix[x, y] != captchaLettersColor:
50
- image.putpixel((x, y), WHITE_RGB)
51
-
52
- image = ImageEnhance.Contrast(image).enhance(500)
53
-
54
- for y in range(image.size[1]):
55
- for x in range(image.size[0]):
56
- if pix[x, y] == captchaLettersColor:
57
- p1 = pix[x + 1, y]
58
- p2 = pix[x - 1, y]
59
- p3 = pix[x, y + 1]
60
- p4 = pix[x, y - 1]
61
- p5 = pix[x + 2, y]
62
- p6 = pix[x - 2, y]
63
- p7 = pix[x, y + 2]
64
- p8 = pix[x, y - 2]
65
- if p1 != captchaLettersColor:
66
- image.putpixel((x + 1, y), captchaLettersColor)
67
- if p2 != captchaLettersColor:
68
- image.putpixel((x - 1, y), captchaLettersColor)
69
- if p3 != captchaLettersColor:
70
- image.putpixel((x, y + 1), captchaLettersColor)
71
- if p4 != captchaLettersColor:
72
- image.putpixel((x, y - 1), captchaLettersColor)
73
- if p5 != captchaLettersColor:
74
- image.putpixel((x + 2, y), captchaLettersColor)
75
- if p6 != captchaLettersColor:
76
- image.putpixel((x - 2, y), captchaLettersColor)
77
- if p7 != captchaLettersColor:
78
- image.putpixel((x, y + 2), captchaLettersColor)
79
- if p8 != captchaLettersColor:
80
- image.putpixel((x, y - 2), captchaLettersColor)
81
-
82
- image = ImageEnhance.Contrast(image).enhance(1200)
83
-
84
- resized = image.resize((image.size[0] * 5, image.size[1] * 5))
85
-
86
- decoded = pytesseract.image_to_string(resized, config = "--psm 13 --oem 3 -c tessedit_char_whitelist=23456789", lang = "eng")
87
-
88
- return {"solution": decoded}