LPX commited on
Commit
1a8be6b
·
1 Parent(s): 179d07c

feat(UX): add image augmentation option for prediction

Browse files

- add "augment" parameter to functions-* predict_image_with_html
- add "augment_image" function
- add extra Gradio Accordion checkbox for image augmentation

Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -200,12 +200,15 @@ def generate_results_html(results):
200
  """
201
  return html_content
202
 
203
- def predict_image_with_html(img, confidence_threshold):
204
- img_pil, results = predict_image(img, confidence_threshold)
 
 
 
 
205
  html_content = generate_results_html(results)
206
  return img_pil, html_content
207
-
208
- # Define the Gradio interface
209
  with gr.Blocks() as iface:
210
  gr.Markdown("# AI Generated Image / Deepfake Detection Models Evaluation")
211
 
@@ -214,7 +217,8 @@ with gr.Blocks() as iface:
214
  image_input = gr.Image(label="Upload Image to Analyze", sources=['upload'], type='pil')
215
  with gr.Accordion("Settings", open=False, elem_id="settings_accordion"):
216
  confidence_slider = gr.Slider(0.0, 1.0, value=0.5, step=0.01, label="Confidence Threshold")
217
- inputs = [image_input, confidence_slider]
 
218
  predict_button = gr.Button("Predict")
219
  with gr.Column(scale=2):
220
  with gr.Accordion("Project OpenSight - Model Evaluations & Playground", open=False, elem_id="project_accordion"):
@@ -224,9 +228,6 @@ with gr.Blocks() as iface:
224
  results_html = gr.HTML(label="Model Predictions")
225
  outputs = [image_output, results_html]
226
 
227
- # gr.Button("Predict").click(fn=predict_image_with_html, inputs=inputs, outputs=outputs)
228
-
229
-
230
  predict_button.click(
231
  fn=predict_image_with_html,
232
  inputs=inputs,
 
200
  """
201
  return html_content
202
 
203
+ def predict_image_with_html(img, confidence_threshold, augment):
204
+ if augment:
205
+ img_pil, _ = augment_image(img)
206
+ else:
207
+ img_pil = img
208
+ img_pil, results = predict_image(img_pil, confidence_threshold)
209
  html_content = generate_results_html(results)
210
  return img_pil, html_content
211
+
 
212
  with gr.Blocks() as iface:
213
  gr.Markdown("# AI Generated Image / Deepfake Detection Models Evaluation")
214
 
 
217
  image_input = gr.Image(label="Upload Image to Analyze", sources=['upload'], type='pil')
218
  with gr.Accordion("Settings", open=False, elem_id="settings_accordion"):
219
  confidence_slider = gr.Slider(0.0, 1.0, value=0.5, step=0.01, label="Confidence Threshold")
220
+ augment_checkbox = gr.Checkbox(label="Augment Image", value=False)
221
+ inputs = [image_input, confidence_slider, augment_checkbox]
222
  predict_button = gr.Button("Predict")
223
  with gr.Column(scale=2):
224
  with gr.Accordion("Project OpenSight - Model Evaluations & Playground", open=False, elem_id="project_accordion"):
 
228
  results_html = gr.HTML(label="Model Predictions")
229
  outputs = [image_output, results_html]
230
 
 
 
 
231
  predict_button.click(
232
  fn=predict_image_with_html,
233
  inputs=inputs,