Spaces:
Running
Running
Upload 6 files
Browse files- 2cegf.png +0 -0
- app.py +47 -0
- captcha2.h5 +3 -0
- requirements.txt +8 -0
- yf424.png +0 -0
- yxd7m.png +0 -0
2cegf.png
ADDED
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Define function to predict captcha
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import string
|
5 |
+
import gradio as gr
|
6 |
+
import tensorflow as tf
|
7 |
+
import os
|
8 |
+
|
9 |
+
model = tf.keras.models.load_model("captcha2.h5")
|
10 |
+
symbols = string.ascii_lowercase + "0123456789"
|
11 |
+
|
12 |
+
|
13 |
+
def predict(img):
|
14 |
+
# Resize image
|
15 |
+
img = cv2.resize(img, (200, 50), interpolation=cv2.INTER_AREA)
|
16 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
17 |
+
# Normalize image
|
18 |
+
img = img / 255.0
|
19 |
+
|
20 |
+
# Pass image to model
|
21 |
+
res = np.array(model.predict(img[np.newaxis, :, :, np.newaxis]))
|
22 |
+
|
23 |
+
# Decode prediction
|
24 |
+
ans = np.reshape(res, (5, 36))
|
25 |
+
l_ind = []
|
26 |
+
probs = []
|
27 |
+
for a in ans:
|
28 |
+
l_ind.append(np.argmax(a))
|
29 |
+
|
30 |
+
capt = ''
|
31 |
+
for l in l_ind:
|
32 |
+
capt += symbols[l]
|
33 |
+
return capt
|
34 |
+
|
35 |
+
|
36 |
+
def captcha(img):
|
37 |
+
prediction = predict(img)
|
38 |
+
|
39 |
+
return prediction
|
40 |
+
|
41 |
+
|
42 |
+
gr.Interface(fn=captcha, inputs="image", outputs="text",
|
43 |
+
title="Enter Alphanumeric Captcha Image" , examples=[
|
44 |
+
os.path.join(os.path.dirname(__file__), "./2cegf.png"),
|
45 |
+
os.path.join(os.path.dirname(__file__), "./yf424.png"),
|
46 |
+
os.path.join(os.path.dirname(__file__), "./yxd7m.png")
|
47 |
+
]).launch()
|
captcha2.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a9d54e89019bce4e50d8955853d0dd462c771804c64074fddbac7fd558cc815a
|
3 |
+
size 21955808
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
pandas
|
3 |
+
keras
|
4 |
+
tensorflow
|
5 |
+
opencv-python
|
6 |
+
os
|
7 |
+
string
|
8 |
+
gradio
|
yf424.png
ADDED
yxd7m.png
ADDED