benjaminStreltzin commited on
Commit
074b0e2
·
verified ·
1 Parent(s): 991fbeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -16,6 +16,7 @@ def predict(image: Image.Image):
16
  return result, f"Confidence: {confidence:.2f}%"
17
 
18
  def report_feedback():
 
19
  if last_prediction is not None:
20
  image, predicted_label = last_prediction
21
  correct_label = 1 if predicted_label == 0 else 0 # Invert the label
@@ -24,20 +25,20 @@ def report_feedback():
24
  return "No prediction available to report."
25
 
26
  # Define the Gradio interface for prediction
27
- demo = gr.Interface(
28
- fn=predict,
29
- inputs=gr.Image(type="pil"),
30
- outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Confidence")],
31
- title="Vision Transformer Model",
32
- description="Upload an image to classify it using the Vision Transformer model.",
33
- theme=gr.themes.Soft()
34
- )
35
-
36
- # Define the feedback button
37
- feedback_button = gr.Button("The model was wrong")
38
- feedback_button.click(report_feedback)
 
39
 
40
  # Launch the Gradio interface
41
  if __name__ == "__main__":
42
- demo.launch(share=True)
43
- feedback_button.launch()
 
16
  return result, f"Confidence: {confidence:.2f}%"
17
 
18
  def report_feedback():
19
+ global last_prediction
20
  if last_prediction is not None:
21
  image, predicted_label = last_prediction
22
  correct_label = 1 if predicted_label == 0 else 0 # Invert the label
 
25
  return "No prediction available to report."
26
 
27
  # Define the Gradio interface for prediction
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("### Vision Transformer Model")
30
+ gr.Markdown("Upload an image to classify it using the Vision Transformer model.")
31
+
32
+ image_input = gr.Image(type="pil", label="Upload Image")
33
+ prediction_output = gr.Textbox(label="Prediction")
34
+ confidence_output = gr.Textbox(label="Confidence")
35
+
36
+ submit_btn = gr.Button("Submit")
37
+ feedback_btn = gr.Button("The model was wrong")
38
+
39
+ submit_btn.click(predict, inputs=image_input, outputs=[prediction_output, confidence_output])
40
+ feedback_btn.click(report_feedback)
41
 
42
  # Launch the Gradio interface
43
  if __name__ == "__main__":
44
+ demo.launch(share=True)