Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -22,9 +22,18 @@ sample_images = [f"sample_images/{img}" for img in os.listdir("sample_images")]
|
|
| 22 |
# -----------------------------
|
| 23 |
def predict_with_preview(image_name):
|
| 24 |
image_path = image_name
|
|
|
|
| 25 |
# Load image for display
|
| 26 |
img_display = cv2.imread(image_path)
|
| 27 |
img_display = cv2.cvtColor(img_display, cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Process grayscale for prediction
|
| 30 |
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
|
@@ -43,9 +52,6 @@ def predict_with_preview(image_name):
|
|
| 43 |
# Custom CSS
|
| 44 |
# -----------------------------
|
| 45 |
custom_css = """
|
| 46 |
-
.image-container {
|
| 47 |
-
height: 350px !important;
|
| 48 |
-
}
|
| 49 |
textarea {
|
| 50 |
min-height: 130px !important;
|
| 51 |
font-size: 18px !important;
|
|
@@ -54,7 +60,7 @@ textarea {
|
|
| 54 |
"""
|
| 55 |
|
| 56 |
# -----------------------------
|
| 57 |
-
# Gradio App
|
| 58 |
# -----------------------------
|
| 59 |
with gr.Blocks(css=custom_css, theme="soft") as demo:
|
| 60 |
gr.Markdown("## 🔐 CAPTCHA Reader")
|
|
@@ -62,10 +68,10 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
| 62 |
with gr.Row():
|
| 63 |
with gr.Column():
|
| 64 |
image_input = gr.Dropdown(choices=sample_images, label="Choose CAPTCHA")
|
| 65 |
-
submit_btn = gr.Button("Submit")
|
| 66 |
|
| 67 |
with gr.Column():
|
| 68 |
-
image_output = gr.Image(label="Selected Image
|
| 69 |
text_output = gr.Textbox(label="Prediction")
|
| 70 |
|
| 71 |
submit_btn.click(fn=predict_with_preview, inputs=image_input, outputs=[image_output, text_output])
|
|
@@ -73,4 +79,4 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
| 73 |
# -----------------------------
|
| 74 |
# Launch App
|
| 75 |
# -----------------------------
|
| 76 |
-
demo.launch()
|
|
|
|
| 22 |
# -----------------------------
|
| 23 |
def predict_with_preview(image_name):
|
| 24 |
image_path = image_name
|
| 25 |
+
|
| 26 |
# Load image for display
|
| 27 |
img_display = cv2.imread(image_path)
|
| 28 |
img_display = cv2.cvtColor(img_display, cv2.COLOR_BGR2RGB)
|
| 29 |
+
|
| 30 |
+
# 🔍 ZOOM IMAGE HERE - 5x bigger
|
| 31 |
+
zoom_factor = 5
|
| 32 |
+
height, width = img_display.shape[:2]
|
| 33 |
+
new_width = width * zoom_factor
|
| 34 |
+
new_height = height * zoom_factor
|
| 35 |
+
img_display = cv2.resize(img_display, (new_width, new_height), interpolation=cv2.INTER_NEAREST)
|
| 36 |
+
# INTER_NEAREST برای حفظ پیکسلهای واضح
|
| 37 |
|
| 38 |
# Process grayscale for prediction
|
| 39 |
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
|
|
|
| 52 |
# Custom CSS
|
| 53 |
# -----------------------------
|
| 54 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
| 55 |
textarea {
|
| 56 |
min-height: 130px !important;
|
| 57 |
font-size: 18px !important;
|
|
|
|
| 60 |
"""
|
| 61 |
|
| 62 |
# -----------------------------
|
| 63 |
+
# Gradio App
|
| 64 |
# -----------------------------
|
| 65 |
with gr.Blocks(css=custom_css, theme="soft") as demo:
|
| 66 |
gr.Markdown("## 🔐 CAPTCHA Reader")
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
| 70 |
image_input = gr.Dropdown(choices=sample_images, label="Choose CAPTCHA")
|
| 71 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
| 72 |
|
| 73 |
with gr.Column():
|
| 74 |
+
image_output = gr.Image(label="Selected Image (5x Zoomed)")
|
| 75 |
text_output = gr.Textbox(label="Prediction")
|
| 76 |
|
| 77 |
submit_btn.click(fn=predict_with_preview, inputs=image_input, outputs=[image_output, text_output])
|
|
|
|
| 79 |
# -----------------------------
|
| 80 |
# Launch App
|
| 81 |
# -----------------------------
|
| 82 |
+
demo.launch()
|