beppefolder commited on
Commit
69a4842
·
verified ·
1 Parent(s): e9b249c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -18
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
- # # **🎨 Customized Interface**
52
- demo = gr.Interface(
53
- fn=classify_img,
54
- inputs=[
55
- gr.Image(type="pil"),
56
- gr.Slider(minimum=0.5, maximum=1.0, value=0.7, step=0.1, label="Classification Threshold")
57
- ],
58
- outputs=[
59
- gr.Textbox(label="Prediction", interactive=False),
60
- gr.Textbox(label="Confidence Score", interactive=False),
61
- ],
62
- title="🖼️✟ Ex-Voto Image Classifier",
63
- description="📸 **Upload an image** to check if it's an **Ex-Voto** painting!",
64
- theme="soft",
65
- allow_flagging="never",
66
- live=False, # Avoids auto-updating; requires a button click
67
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  # Launch App
70
- demo.launch(share=True)
 
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()