Spaces:
Paused
Paused
update
Browse files4 unmodified lines5678910111213141516171813 unmodified lines32333435363738394041424344454647484950515253544 unmodified linesimport numpy as npimport os# Load model and encodermodel = tf.keras.models.load_model("model/captcha_model.h5")with open("model/encoder.pkl", "rb") as f:encoder = pickle.load(f)# List of available sample imagessample_images = [f"sample_images/{img}" for img in os.listdir("sample_images")]def predict_with_preview(image_name):image_path = image_name# Load image for display13 unmodified linesreturn img_display, f"โ Predicted: {''.join(pred_chars)}\n๐ Original: {original}"demo = gr.Interface(fn=predict_with_preview,inputs=gr.Dropdown(choices=sample_images, label="Choose CAPTCHA"),outputs=[gr.Image(label="Selected Image"), gr.Textbox(label="Prediction")],title="๐ CAPTCHA Reader",theme="soft")custom_css = """.image-container {height: 350px !important;}textarea.svelte-1ae7ssi {min-height: 120px !important;font-size: 18px !important;}"""demo.launch(css=custom_css)4 unmodified lines567891011121314151617181920212223242513 unmodified lines39404142434445464748495051525354555657585960616263646566676869707172737475764 unmodified linesimport numpy as npimport os# -----------------------------# Load model and encoder# -----------------------------model = tf.keras.models.load_model("model/captcha_model.h5")with open("model/encoder.pkl", "rb") as f:encoder = pickle.load(f)# -----------------------------# List of available sample images# -----------------------------sample_images = [f"sample_images/{img}" for img in os.listdir("sample_images")]# -----------------------------# Prediction Function# -----------------------------def predict_with_preview(image_name):image_path = image_name# Load image for display13 unmodified linesreturn img_display, f"โ Predicted: {''.join(pred_chars)}\n๐ Original: {original}"# -----------------------------# Custom CSS# -----------------------------custom_css = """.image-container {height: 350px !important;}textarea {min-height: 130px !important;font-size: 18px !important;line-height: 1.6 !important;}"""# -----------------------------# Gradio App (new structure)# -----------------------------with gr.Blocks(css=custom_css, theme="soft") as demo:gr.Markdown("## ๐ CAPTCHA Reader")with gr.Row():with gr.Column():image_input = gr.Dropdown(choices=sample_images, label="Choose CAPTCHA")submit_btn = gr.Button("Submit")with gr.Column():image_output = gr.Image(label="Selected Image")text_output = gr.Textbox(label="Prediction")submit_btn.click(fn=predict_with_preview, inputs=image_input, outputs=[image_output, text_output])# -----------------------------# Launch App# -----------------------------demo.launch()
app.py+34-12