Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,24 +47,45 @@ def classify_img(img, threshold):
|
|
| 47 |
confidence = f"The probability that the image is an ex-voto is: {score:.2%}"
|
| 48 |
return label, confidence
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Launch App
|
| 70 |
-
demo.launch(
|
|
|
|
| 47 |
confidence = f"The probability that the image is an ex-voto is: {score:.2%}"
|
| 48 |
return label, confidence
|
| 49 |
|
| 50 |
+
example_images = [['examples/exvoto1.jpg', None],
|
| 51 |
+
['examples/exvoto2.jpg', None],
|
| 52 |
+
['examples/nonexvoto1.jpg', None],
|
| 53 |
+
['examples/nonexvoto2.jpg', None],
|
| 54 |
+
['examples/natural1.jpg', None],
|
| 55 |
+
['examples/natural2.jpg', None],]
|
| 56 |
|
| 57 |
+
# Function to Clear Outputs When a New Image is Uploaded
|
| 58 |
+
def clear_outputs(img):
|
| 59 |
+
return gr.update(value=""), gr.update(value="")
|
| 60 |
+
|
| 61 |
+
# Gradio Interface
|
| 62 |
+
with gr.Blocks() as demo:
|
| 63 |
+
gr.Markdown("## 🖼️✟ Ex-Voto Image Classifier")
|
| 64 |
+
gr.Markdown("📸 **Upload an image** to check if it's an **Ex-Voto** painting!")
|
| 65 |
+
|
| 66 |
+
with gr.Row():
|
| 67 |
+
with gr.Column(scale=2): # Left section: Image upload & slider
|
| 68 |
+
img_input = gr.Image(type="pil")
|
| 69 |
+
threshold_slider = gr.Slider(
|
| 70 |
+
minimum=0.5, maximum=1.0, value=0.7, step=0.1, label="Classification Threshold"
|
| 71 |
+
)
|
| 72 |
+
submit_btn = gr.Button("Classify")
|
| 73 |
+
|
| 74 |
+
with gr.Column(scale=1): # Right section: Prediction & Confidence
|
| 75 |
+
prediction_output = gr.Textbox(label="Prediction", interactive=False)
|
| 76 |
+
confidence_output = gr.Textbox(label="Confidence Score", interactive=False)
|
| 77 |
+
|
| 78 |
+
# Clear outputs when a new image is uploaded
|
| 79 |
+
img_input.change(fn=clear_outputs, inputs=[img_input], outputs=[prediction_output, confidence_output])
|
| 80 |
+
|
| 81 |
+
# Submit button triggers classification
|
| 82 |
+
submit_btn.click(fn=classify_img, inputs=[img_input, threshold_slider], outputs=[prediction_output, confidence_output])
|
| 83 |
+
|
| 84 |
+
# Example images (Only show images, no threshold value)
|
| 85 |
+
gr.Examples(
|
| 86 |
+
examples=example_images,
|
| 87 |
+
inputs=[img_input]
|
| 88 |
+
)
|
| 89 |
|
| 90 |
# Launch App
|
| 91 |
+
demo.launch()
|