Adonai Vera commited on
Commit
fbabf41
·
1 Parent(s): e0834a0

Added the full name in the prediction

Browse files
Files changed (1) hide show
  1. app.py +74 -1
app.py CHANGED
@@ -6,6 +6,74 @@ from PIL import Image
6
  # Initialize the pipeline with your model
7
  pipe = pipeline("image-classification", model="SubterraAI/ofwat_defects_classification")
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def classify_image(image):
11
  # Convert the input image to PIL format
@@ -13,9 +81,12 @@ def classify_image(image):
13
 
14
  # Classify the image using the pipeline
15
  res = pipe(PIL_image)
 
 
 
16
 
17
  # Extract labels and scores
18
- return {dic["label"]: dic["score"] for dic in res}
19
 
20
  # Create the Gradio interface
21
  iface = gr.Interface(
@@ -30,6 +101,8 @@ iface = gr.Interface(
30
  ],
31
  description="Upload an image to classify its material.",
32
  title="Defects Classification with AI by Subterra"
 
 
33
  )
34
 
35
  # Launch the interface
 
6
  # Initialize the pipeline with your model
7
  pipe = pipeline("image-classification", model="SubterraAI/ofwat_defects_classification")
8
 
9
+ defect_dict = {
10
+ "CL": "Crack Longitudinal",
11
+ "CLJ": "Crack Longitudinal at Joint",
12
+ "CC": "Crack Circumferential",
13
+ "CCJ": "Crack Circumferential at Joint",
14
+ "CM": "Crack Multiple",
15
+ "CMJ": "Crack Multiple at Joint",
16
+ "CS": "Crack Spiral",
17
+ "FL": "Fracture Longitudinal",
18
+ "FC": "Fracture Circumferential",
19
+ "FM": "Fracture Multiple",
20
+ "FS": "Fracture Spiral",
21
+ "B": "Broken",
22
+ "BJ": "Broken Pipe at Joint",
23
+ "H": "Hole",
24
+ "D": "Deformation (Not Brick)",
25
+ "XB": "Collapse",
26
+ "JD": "Joint Displaced",
27
+ "JDM": "Joint Displaced Medium",
28
+ "JDL": "Joint Displaced Large",
29
+ "OJ": "Open Joint",
30
+ "OJM": "Open Joint Medium",
31
+ "OJL": "Open Joint Large",
32
+ "SW": "Increased Roughness",
33
+ "SAV": "Visible Aggregate",
34
+ "SAP": "Aggregate Projecting",
35
+ "SRV": "Visible Reinforcement",
36
+ "SRP": "Reinforcement Projecting",
37
+ "SRC": "Corroded Reinforcement",
38
+ "SS": "Surface Damage Spalling",
39
+ "SZ": "Other Damage",
40
+ "LX": "Line Defect",
41
+ "WXC": "Weld Failure Circumferential",
42
+ "WXL": "Weld Failure Longitudinal",
43
+ "WXS": "Weld Failure Spiral",
44
+ "RXM": "Defective Repair, part of wall missing",
45
+ "RX": "Defective Repair",
46
+ "DB": "Displaced bricks",
47
+ "MB": "Missing bricks",
48
+ "DI": "Dropped Invert",
49
+ "EL": "Encrustation/Scale Light",
50
+ "ESL": "Encrustation/Scale Light",
51
+ "EM": "Encrustation/Scale Medium",
52
+ "ESM": "Encrustation/Scale Medium",
53
+ "EH": "Encrustation/Scale Heavy",
54
+ "ESH": "Encrustation/Scale Heavy",
55
+ "DEG": "Debris Grease",
56
+ "DES": "Debris Silt",
57
+ "RF": "Roots Fine",
58
+ "RM": "Roots Mass",
59
+ "RT": "Roots Tap",
60
+ "IS(J)": "Infiltration Light Seeping Joint",
61
+ "ID(J)": "Infiltration Light Dripping Joint",
62
+ "IR(J)": "Infiltration Moderate Running Joint",
63
+ "IRG(J)": "Infiltration Severe Gusher Joint",
64
+ "CNI": "Connection Intruding",
65
+ "CX": "Connection Defective",
66
+ "SR": "Sealing Ring Intruding",
67
+ "SRB": "Sealing Ring Broken",
68
+ "SO": "Other sealent intruding",
69
+ "CU": "Camera Underwater"
70
+ }
71
+
72
+ def replace_label_with_full_name(res, defect_dict_key_code):
73
+ # Check if the label in the result is in the dictionary
74
+ # If it is, replace it with the full name
75
+ return {defect_dict_key_code.get(dic["label"], dic["label"]): dic["score"] for dic in res}
76
+
77
 
78
  def classify_image(image):
79
  # Convert the input image to PIL format
 
81
 
82
  # Classify the image using the pipeline
83
  res = pipe(PIL_image)
84
+
85
+ replaced_res = replace_label_with_full_name(res, defect_dict)
86
+
87
 
88
  # Extract labels and scores
89
+ return {dic["label"]: dic["score"] for dic in replaced_res}
90
 
91
  # Create the Gradio interface
92
  iface = gr.Interface(
 
101
  ],
102
  description="Upload an image to classify its material.",
103
  title="Defects Classification with AI by Subterra"
104
+ #allow_flagging="manual",
105
+ #flagging_options=["obstruction", "no_obstruction"]
106
  )
107
 
108
  # Launch the interface