LPX
commited on
Commit
·
17ebb8f
1
Parent(s):
39fbd8c
🐛 fix(interface): update image processing wih Augment & Predict Button
Browse files- added ability to perform image preprocessing using Augment & Predict Button【feat】
- update label to be more informative 【style】
```
app.py
CHANGED
@@ -240,7 +240,7 @@ def predict_image_with_html(img, confidence_threshold, augment_methods, rotate_d
|
|
240 |
ela_img_1 = ELA(img_pil, scale=100, alpha=0.66)
|
241 |
ela_img_2 = ELA(img_pil, scale=50, alpha=0.5)
|
242 |
|
243 |
-
forensics_images = [ela_img_1, ela_img_2, gradient_image, minmax_image]
|
244 |
|
245 |
html_content = generate_results_html(results)
|
246 |
return img_pil, forensics_images, html_content
|
@@ -254,7 +254,7 @@ with gr.Blocks() as iface:
|
|
254 |
with gr.Row():
|
255 |
with gr.Column(scale=1):
|
256 |
image_input = gr.Image(label="Upload Image to Analyze", sources=['upload'], type='pil')
|
257 |
-
with gr.Accordion("Settings", open=False, elem_id="settings_accordion"):
|
258 |
augment_checkboxgroup = gr.CheckboxGroup(["rotate", "add_noise", "sharpen"], label="Augmentation Methods")
|
259 |
rotate_slider = gr.Slider(0, 45, value=2, step=1, label="Rotate Degrees", visible=False)
|
260 |
noise_slider = gr.Slider(0, 50, value=4, step=1, label="Noise Level", visible=False)
|
@@ -262,7 +262,8 @@ with gr.Blocks() as iface:
|
|
262 |
confidence_slider = gr.Slider(0.0, 1.0, value=0.75, step=0.05, label="Confidence Threshold")
|
263 |
inputs = [image_input, confidence_slider, augment_checkboxgroup, rotate_slider, noise_slider, sharpen_slider]
|
264 |
predict_button = gr.Button("Predict")
|
265 |
-
|
|
|
266 |
forensics_gallery = gr.Gallery(label="Post Processed Images", visible=True)
|
267 |
|
268 |
|
@@ -281,6 +282,11 @@ with gr.Blocks() as iface:
|
|
281 |
inputs=inputs,
|
282 |
outputs=outputs
|
283 |
)
|
|
|
|
|
|
|
|
|
|
|
284 |
predict_button.click(
|
285 |
fn=None,
|
286 |
js="() => {document.getElementById('project_accordion').open = false;}", # Close the project accordion
|
|
|
240 |
ela_img_1 = ELA(img_pil, scale=100, alpha=0.66)
|
241 |
ela_img_2 = ELA(img_pil, scale=50, alpha=0.5)
|
242 |
|
243 |
+
forensics_images = [img_pil, ela_img_1, ela_img_2, gradient_image, minmax_image]
|
244 |
|
245 |
html_content = generate_results_html(results)
|
246 |
return img_pil, forensics_images, html_content
|
|
|
254 |
with gr.Row():
|
255 |
with gr.Column(scale=1):
|
256 |
image_input = gr.Image(label="Upload Image to Analyze", sources=['upload'], type='pil')
|
257 |
+
with gr.Accordion("Settings (Optional)", open=False, elem_id="settings_accordion"):
|
258 |
augment_checkboxgroup = gr.CheckboxGroup(["rotate", "add_noise", "sharpen"], label="Augmentation Methods")
|
259 |
rotate_slider = gr.Slider(0, 45, value=2, step=1, label="Rotate Degrees", visible=False)
|
260 |
noise_slider = gr.Slider(0, 50, value=4, step=1, label="Noise Level", visible=False)
|
|
|
262 |
confidence_slider = gr.Slider(0.0, 1.0, value=0.75, step=0.05, label="Confidence Threshold")
|
263 |
inputs = [image_input, confidence_slider, augment_checkboxgroup, rotate_slider, noise_slider, sharpen_slider]
|
264 |
predict_button = gr.Button("Predict")
|
265 |
+
augment_button = gr.Button("Augment & Predict")
|
266 |
+
image_output = gr.Image(label="Processed Image", visible=False)
|
267 |
forensics_gallery = gr.Gallery(label="Post Processed Images", visible=True)
|
268 |
|
269 |
|
|
|
282 |
inputs=inputs,
|
283 |
outputs=outputs
|
284 |
)
|
285 |
+
augment_button.click( # Connect Augment button to the function
|
286 |
+
fn=predict_image_with_html,
|
287 |
+
inputs=[image_input, confidence_slider, gr.CheckboxGroup(["rotate", "add_noise", "sharpen"]), rotate_slider, noise_slider, sharpen_slider],
|
288 |
+
outputs=outputs
|
289 |
+
)
|
290 |
predict_button.click(
|
291 |
fn=None,
|
292 |
js="() => {document.getElementById('project_accordion').open = false;}", # Close the project accordion
|