File size: 2,161 Bytes
988e9db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import gradio as gr
import cv2
import numpy as np
from captcha_solver_hf import solve_captcha

def predict_captcha(image):
    if image is None:
        return "Please upload an image."
    img_array = np.array(image)
    img_cv = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
    result = solve_captcha(img_cv)
    return result

# Example images (replace these with actual CAPTCHA images)
examples = [
    "example_captcha1.png",
    "example_captcha2.png",
    "example_captcha3.png"
]

css = """

.gradio-container {

    font-family: 'Arial', sans-serif;

}

.gr-button {

    color: white;

    border-color: black;

    background: linear-gradient(45deg, #007bff, #00bcd4);

}

.gr-button:hover {

    background: linear-gradient(45deg, #0056b3, #008ba3);

}

.gr-form {

    flex-direction: column;

    align-items: center;

}

.gr-image-input {

    width: 100% !important;

    max-width: 400px;

    margin: auto;

}

.footer {

    margin-top: 20px;

    text-align: center;

    color: #666;

}

h1, h3 {

    text-align: center;

}

"""

with gr.Blocks(css=css) as iface:
    gr.Markdown(
    """

    # CAPTCHA Solver

    ### Unlock the Power of AI-Driven CAPTCHA Recognition

    Upload your CAPTCHA image and let our advanced AI model decipher it instantly!

    """
    )
    with gr.Column(scale=1):
        input_image = gr.Image(type="numpy", label="Upload CAPTCHA Image")
        output_text = gr.Textbox(label="Predicted Text")
    
    solve_button = gr.Button("Solve CAPTCHA", variant="primary")
    solve_button.click(fn=predict_captcha, inputs=input_image, outputs=output_text)
    
    gr.Examples(examples, inputs=input_image)
    
    gr.Markdown(
    """

    ### How It Works

    1. Upload a CAPTCHA image

    2. Click "Solve CAPTCHA"

    3. Get instant results!

    

    Our state-of-the-art AI model processes your image and provides accurate text recognition.

    """
    )
    
    gr.Markdown(
    """

    <div class="footer">

    Developed with ❤️ by Arnav Agarwal | © 2024 All Rights Reserved

    </div>

    """
    )

if __name__ == "__main__":
    iface.launch()