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( """ """ ) if __name__ == "__main__": iface.launch()