Adonai Vera commited on
Commit
0904938
·
1 Parent(s): 5d18012

Improve message

Browse files
Files changed (1) hide show
  1. app.py +4 -23
app.py CHANGED
@@ -40,7 +40,7 @@ def simple_flag(image, label):
40
  commit_message=f"Add image with label {label}"
41
  )
42
 
43
- return "Image saved successfully to Hugging Face dataset."
44
 
45
  def classify_image(image):
46
  # Convert the input image to PIL format
@@ -52,25 +52,6 @@ def classify_image(image):
52
  # Extract labels and scores
53
  return {dic["label"]: dic["score"] for dic in res}
54
 
55
- def save_flagged_image(image, label):
56
- try:
57
- # Convert the input image to PIL format
58
- PIL_image = Image.fromarray(image).convert('RGB')
59
-
60
- # Create the directory for the label if it doesn't exist
61
- label_dir = os.path.join(flagged_data_dir, label)
62
- os.makedirs(label_dir, exist_ok=True)
63
-
64
- # Save the image with a unique filename
65
- img_filename = f"{label}_{hash(image.tobytes())}.png"
66
- img_path = os.path.join(label_dir, img_filename)
67
- PIL_image.save(img_path)
68
-
69
- return "Image saved successfully."
70
- except Exception as e:
71
- print(f"Error during flagging: {e}")
72
- return f"An error occurred: {e}"
73
-
74
  with gr.Blocks() as demo:
75
  gr.Markdown("# Sewer Obstruction Classification with AI by Subterra")
76
  gr.Markdown("Upload an image to view a classification demonstration leveraging the dataset/library of images collected by WRc & United Utilities during The Water Services Regulation Authority (OFWAT) Innovation Challenge – Artificial Intelligence and Sewers. Not only can you see the initial classification, but you as the user can also inform us if the classification is correct. Your response will be used to retrain this model. The team at Subterra would like to thank all of those involved in collecting this dataset as we hope that other groups will use it to further advance technology solutions for the water industry.")
@@ -79,12 +60,12 @@ with gr.Blocks() as demo:
79
  with gr.Column():
80
  img_input = gr.Image()
81
  submit_button = gr.Button("Classify")
82
- examples = gr.Examples(["examples/CS.jpg", "examples/GI.jpg", "examples/PP.jpg"], inputs=img_input)
83
  with gr.Column():
84
  output_label = gr.Label()
85
- flagging_options = gr.Radio(["obstruction", "no_obstruction"])
86
  flag_button = gr.Button("Flag")
87
- flag_status = gr.Textbox(visible=True)
88
 
89
  submit_button.click(classify_image, inputs=img_input, outputs=output_label)
90
  flag_button.click(simple_flag, inputs=[img_input, flagging_options], outputs=flag_status)
 
40
  commit_message=f"Add image with label {label}"
41
  )
42
 
43
+ return "Thank you for your contribution to the open-source world! Your feedback helps us all move towards a clearer future"
44
 
45
  def classify_image(image):
46
  # Convert the input image to PIL format
 
52
  # Extract labels and scores
53
  return {dic["label"]: dic["score"] for dic in res}
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  with gr.Blocks() as demo:
56
  gr.Markdown("# Sewer Obstruction Classification with AI by Subterra")
57
  gr.Markdown("Upload an image to view a classification demonstration leveraging the dataset/library of images collected by WRc & United Utilities during The Water Services Regulation Authority (OFWAT) Innovation Challenge – Artificial Intelligence and Sewers. Not only can you see the initial classification, but you as the user can also inform us if the classification is correct. Your response will be used to retrain this model. The team at Subterra would like to thank all of those involved in collecting this dataset as we hope that other groups will use it to further advance technology solutions for the water industry.")
 
60
  with gr.Column():
61
  img_input = gr.Image()
62
  submit_button = gr.Button("Classify")
63
+ examples = gr.Examples(["examples/CS.jpg", "examples/GI.jpg", "examples/PP.jpg"], label = "Explore Examples", inputs=img_input)
64
  with gr.Column():
65
  output_label = gr.Label()
66
+ flagging_options = gr.Radio(["obstruction", "no_obstruction"], label="Does this classification look off to you? Your sharp eyes can help correct it. Flag any inaccuracies and suggest the right label!")
67
  flag_button = gr.Button("Flag")
68
+ flag_status = gr.Textbox(label = "Every flag you submit polishes our dataset. Thanks for being an active participant in our open-source journey.",visible=True)
69
 
70
  submit_button.click(classify_image, inputs=img_input, outputs=output_label)
71
  flag_button.click(simple_flag, inputs=[img_input, flagging_options], outputs=flag_status)