Spaces:
Sleeping
Sleeping
first commit
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- app.py +43 -0
- model/captcha_model.h5 +3 -0
- model/encoder.pkl +3 -0
- requirements.txt +5 -0
- sample_images/222X.png +0 -0
- sample_images/226U.png +0 -0
- sample_images/2274.png +0 -0
- sample_images/22A6.png +0 -0
- sample_images/22BJ.png +0 -0
- sample_images/22HS.png +0 -0
- sample_images/22KD.png +0 -0
- sample_images/22L9.png +0 -0
- sample_images/22NR.png +0 -0
- sample_images/22PL.png +0 -0
- sample_images/22SS.png +0 -0
- sample_images/22UX.png +0 -0
- sample_images/23D7.png +0 -0
- sample_images/23EZ.png +0 -0
- sample_images/23FQ.png +0 -0
- sample_images/23T2.png +0 -0
- sample_images/23XT.png +0 -0
- sample_images/243B.png +0 -0
- sample_images/248C.png +0 -0
- sample_images/24FJ.png +0 -0
- sample_images/24FK.png +0 -0
- sample_images/24HA.png +0 -0
- sample_images/24HK.png +0 -0
- sample_images/24XX.png +0 -0
- sample_images/24Z5.png +0 -0
- sample_images/24ZK.png +0 -0
- sample_images/2544.png +0 -0
- sample_images/2552.png +0 -0
- sample_images/256Q.png +0 -0
- sample_images/2582.png +0 -0
- sample_images/25BG.png +0 -0
- sample_images/25MZ.png +0 -0
- sample_images/25Q2.png +0 -0
- sample_images/25VJ.png +0 -0
- sample_images/265P.png +0 -0
- sample_images/267R.png +0 -0
- sample_images/267X.png +0 -0
- sample_images/26AT.png +0 -0
- sample_images/26E4.png +0 -0
- sample_images/26FL.png +0 -0
- sample_images/26GM.png +0 -0
- sample_images/26M3.png +0 -0
- sample_images/26VL.png +0 -0
- sample_images/26WU.png +0 -0
- sample_images/26WY.png +0 -0
- sample_images/273U.png +0 -0
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import pickle
|
| 4 |
+
import cv2
|
| 5 |
+
import numpy as np
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Load model and encoder
|
| 9 |
+
model = tf.keras.models.load_model("model/captcha_model.h5")
|
| 10 |
+
with open("model/encoder.pkl", "rb") as f:
|
| 11 |
+
encoder = pickle.load(f)
|
| 12 |
+
|
| 13 |
+
# List of available sample images
|
| 14 |
+
sample_images = [f"sample_images/{img}" for img in os.listdir("sample_images")]
|
| 15 |
+
|
| 16 |
+
def predict_with_preview(image_name):
|
| 17 |
+
image_path = image_name
|
| 18 |
+
# Load image for display
|
| 19 |
+
img_display = cv2.imread(image_path)
|
| 20 |
+
img_display = cv2.cvtColor(img_display, cv2.COLOR_BGR2RGB)
|
| 21 |
+
|
| 22 |
+
# Process grayscale for prediction
|
| 23 |
+
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
| 24 |
+
img = cv2.bitwise_not(img)
|
| 25 |
+
img = img / 255.0
|
| 26 |
+
|
| 27 |
+
preds = model.predict(np.expand_dims(img, axis=0))
|
| 28 |
+
predicted_indices = [np.argmax(p, axis=1)[0] for p in preds]
|
| 29 |
+
pred_chars = encoder.inverse_transform(predicted_indices)
|
| 30 |
+
|
| 31 |
+
original = os.path.splitext(os.path.basename(image_path))[0]
|
| 32 |
+
|
| 33 |
+
return img_display, f"✅ Predicted: {''.join(pred_chars)}\n📝 Original: {original}"
|
| 34 |
+
|
| 35 |
+
demo = gr.Interface(
|
| 36 |
+
fn=predict_with_preview,
|
| 37 |
+
inputs=gr.Dropdown(choices=sample_images, label="Choose CAPTCHA"),
|
| 38 |
+
outputs=[gr.Image(label="Selected Image"), gr.Textbox(label="Prediction")],
|
| 39 |
+
title="🔐 CAPTCHA Reader",
|
| 40 |
+
theme="soft"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
demo.launch()
|
model/captcha_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e1a980381408241468759613b79d2881665d320222d9d01ac0e7286aaaeace95
|
| 3 |
+
size 12406592
|
model/encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:316f379c0b7468197e23856e18c568f6f38865e03ed0e617713255070452c928
|
| 3 |
+
size 364
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
opencv-python-headless
|
| 4 |
+
numpy
|
| 5 |
+
pillow
|
sample_images/222X.png
ADDED
|
sample_images/226U.png
ADDED
|
sample_images/2274.png
ADDED
|
sample_images/22A6.png
ADDED
|
sample_images/22BJ.png
ADDED
|
sample_images/22HS.png
ADDED
|
sample_images/22KD.png
ADDED
|
sample_images/22L9.png
ADDED
|
sample_images/22NR.png
ADDED
|
sample_images/22PL.png
ADDED
|
sample_images/22SS.png
ADDED
|
sample_images/22UX.png
ADDED
|
sample_images/23D7.png
ADDED
|
sample_images/23EZ.png
ADDED
|
sample_images/23FQ.png
ADDED
|
sample_images/23T2.png
ADDED
|
sample_images/23XT.png
ADDED
|
sample_images/243B.png
ADDED
|
sample_images/248C.png
ADDED
|
sample_images/24FJ.png
ADDED
|
sample_images/24FK.png
ADDED
|
sample_images/24HA.png
ADDED
|
sample_images/24HK.png
ADDED
|
sample_images/24XX.png
ADDED
|
sample_images/24Z5.png
ADDED
|
sample_images/24ZK.png
ADDED
|
sample_images/2544.png
ADDED
|
sample_images/2552.png
ADDED
|
sample_images/256Q.png
ADDED
|
sample_images/2582.png
ADDED
|
sample_images/25BG.png
ADDED
|
sample_images/25MZ.png
ADDED
|
sample_images/25Q2.png
ADDED
|
sample_images/25VJ.png
ADDED
|
sample_images/265P.png
ADDED
|
sample_images/267R.png
ADDED
|
sample_images/267X.png
ADDED
|
sample_images/26AT.png
ADDED
|
sample_images/26E4.png
ADDED
|
sample_images/26FL.png
ADDED
|
sample_images/26GM.png
ADDED
|
sample_images/26M3.png
ADDED
|
sample_images/26VL.png
ADDED
|
sample_images/26WU.png
ADDED
|
sample_images/26WY.png
ADDED
|
sample_images/273U.png
ADDED
|