Spaces:
Runtime error
Runtime error
Adonai Vera
commited on
Commit
·
1671151
1
Parent(s):
a9f27ef
add lables material
Browse files- .gitignore +32 -0
- app.py +76 -2
- flagged/log.csv +1 -0
.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
**/*.DS_store
|
| 3 |
+
.vscode
|
| 4 |
+
node_modules
|
| 5 |
+
|
| 6 |
+
__pycache__
|
| 7 |
+
*.py[cod]
|
| 8 |
+
|
| 9 |
+
*.egg-info
|
| 10 |
+
.project
|
| 11 |
+
.pydevproject
|
| 12 |
+
**/*.ipynb_checkpoints
|
| 13 |
+
.idea
|
| 14 |
+
*.swp
|
| 15 |
+
|
| 16 |
+
*~
|
| 17 |
+
|
| 18 |
+
build/
|
| 19 |
+
dist/
|
| 20 |
+
|
| 21 |
+
/eta/
|
| 22 |
+
|
| 23 |
+
/docs/build/
|
| 24 |
+
/docs/source/api/
|
| 25 |
+
|
| 26 |
+
/bin
|
| 27 |
+
/lib
|
| 28 |
+
coverage.xml
|
| 29 |
+
.coverage.*
|
| 30 |
+
pyvenv.cfg
|
| 31 |
+
|
| 32 |
+
flagged/
|
app.py
CHANGED
|
@@ -6,6 +6,78 @@ from PIL import Image
|
|
| 6 |
# Initialize the pipeline with your model
|
| 7 |
pipe = pipeline("image-classification", model="SubterraAI/ofwat_material_classification")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def classify_image(image):
|
| 10 |
# Convert the input image to PIL format
|
| 11 |
PIL_image = Image.fromarray(image).convert('RGB')
|
|
@@ -14,7 +86,7 @@ def classify_image(image):
|
|
| 14 |
res = pipe(PIL_image)
|
| 15 |
|
| 16 |
# Extract labels and scores
|
| 17 |
-
return
|
| 18 |
|
| 19 |
|
| 20 |
# Create the Gradio interface
|
|
@@ -29,7 +101,9 @@ iface = gr.Interface(
|
|
| 29 |
["examples/RC.jpg"]
|
| 30 |
],
|
| 31 |
description="Upload an image to classify its material.",
|
| 32 |
-
title="Material 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_material_classification")
|
| 8 |
|
| 9 |
+
material_codes = {
|
| 10 |
+
"AC": "Asphalt Concrete",
|
| 11 |
+
"BL": "Block",
|
| 12 |
+
"BR": "Brick",
|
| 13 |
+
"CI": "Cast Iron",
|
| 14 |
+
"CO": "Concrete",
|
| 15 |
+
"CS": "Corrugated Steel",
|
| 16 |
+
"DI": "Ductile Iron",
|
| 17 |
+
"EP": "Epoxy",
|
| 18 |
+
"GI": "Galvanized Iron",
|
| 19 |
+
"MAR": "Masonry",
|
| 20 |
+
"N": "Not specified, possibly a custom abbreviation",
|
| 21 |
+
"OTH": "Other",
|
| 22 |
+
"PE": "Polyethylene",
|
| 23 |
+
"PF": "Plywood-Faced",
|
| 24 |
+
"PP": "Polypropylene",
|
| 25 |
+
"PVC": "Polyvinyl Chloride",
|
| 26 |
+
"RC": "Reinforced Concrete",
|
| 27 |
+
"ST": "Steel",
|
| 28 |
+
"U": "Unspecified, possibly a custom abbreviation",
|
| 29 |
+
"UPVC": "Unplasticized Polyvinyl Chloride",
|
| 30 |
+
"VC": "Vinyl Coated",
|
| 31 |
+
"XI": "Extra Impact",
|
| 32 |
+
"XP": "Extruded Polystyrene",
|
| 33 |
+
"Z": "Not specified, possibly a custom abbreviation"
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
material_full_names_list = [
|
| 37 |
+
'Asphalt Concrete',
|
| 38 |
+
'Block',
|
| 39 |
+
'Brick',
|
| 40 |
+
'Cast Iron',
|
| 41 |
+
'Concrete',
|
| 42 |
+
'Corrugated Steel',
|
| 43 |
+
'Ductile Iron',
|
| 44 |
+
'Epoxy',
|
| 45 |
+
'Galvanized Iron',
|
| 46 |
+
'Masonry',
|
| 47 |
+
'Not specified, possibly a custom abbreviation',
|
| 48 |
+
'Other',
|
| 49 |
+
'Polyethylene',
|
| 50 |
+
'Plywood-Faced',
|
| 51 |
+
'Polypropylene',
|
| 52 |
+
'Polyvinyl Chloride',
|
| 53 |
+
'Reinforced Concrete',
|
| 54 |
+
'Steel',
|
| 55 |
+
'Unspecified, possibly a custom abbreviation',
|
| 56 |
+
'Unplasticized Polyvinyl Chloride',
|
| 57 |
+
'Vinyl Coated',
|
| 58 |
+
'Extra Impact',
|
| 59 |
+
'Extruded Polystyrene',
|
| 60 |
+
'Not specified, possibly a custom abbreviation',
|
| 61 |
+
'Vitrified Clay Lined'
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
def replace_label_with_full_name(res, defect_dict_key_code):
|
| 65 |
+
new_res = {}
|
| 66 |
+
for dic in res:
|
| 67 |
+
# Splitting the label to handle possible suffix
|
| 68 |
+
parts = dic["label"].split('_', 1)
|
| 69 |
+
code = parts[0]
|
| 70 |
+
suffix = '_' + parts[1] if len(parts) > 1 else ''
|
| 71 |
+
|
| 72 |
+
# Replacing the code with its full name, if it exists in the dictionary
|
| 73 |
+
full_name = defect_dict_key_code.get(code, code)
|
| 74 |
+
|
| 75 |
+
# Constructing the new label with the suffix if it exists
|
| 76 |
+
new_label = full_name + suffix
|
| 77 |
+
new_res[new_label] = dic["score"]
|
| 78 |
+
|
| 79 |
+
return new_res
|
| 80 |
+
|
| 81 |
def classify_image(image):
|
| 82 |
# Convert the input image to PIL format
|
| 83 |
PIL_image = Image.fromarray(image).convert('RGB')
|
|
|
|
| 86 |
res = pipe(PIL_image)
|
| 87 |
|
| 88 |
# Extract labels and scores
|
| 89 |
+
return replace_label_with_full_name(res, material_codes)
|
| 90 |
|
| 91 |
|
| 92 |
# Create the Gradio interface
|
|
|
|
| 101 |
["examples/RC.jpg"]
|
| 102 |
],
|
| 103 |
description="Upload an image to classify its material.",
|
| 104 |
+
title="Material Classification with AI by Subterra",
|
| 105 |
+
allow_flagging="manual",
|
| 106 |
+
flagging_options=material_full_names_list
|
| 107 |
)
|
| 108 |
|
| 109 |
# Launch the interface
|
flagged/log.csv
CHANGED
|
@@ -5,3 +5,4 @@ image,output 0,output 1,flag,username,timestamp
|
|
| 5 |
| GI | Galvanized Iron |
|
| 6 |
| PP | Polypropylene |
|
| 7 |
| RC | Reinforced Concrete |",,,2023-11-27 15:26:38.548865
|
|
|
|
|
|
| 5 |
| GI | Galvanized Iron |
|
| 6 |
| PP | Polypropylene |
|
| 7 |
| RC | Reinforced Concrete |",,,2023-11-27 15:26:38.548865
|
| 8 |
+
"{""path"":""flagged/image/d2b68ddde05e27a540cc/PP.jpg"",""url"":""http://127.0.0.1:7860/file=/private/var/folders/5q/yl8pmxm116g6r3k8fd9gk74m0000gn/T/gradio/12885a897d79141c54ccb542582449159242eaa0/PP.jpg"",""size"":null,""orig_name"":""PP.jpg"",""mime_type"":null}","{""label"":""Vinyl Coated"",""confidences"":[{""label"":""Vinyl Coated"",""confidence"":0.7706952691078186},{""label"":""Polyvinyl Chloride"",""confidence"":0.20648105442523956},{""label"":""Polyethylene"",""confidence"":0.005161861423403025},{""label"":""Plywood-Faced"",""confidence"":0.004196972120553255},{""label"":""Concrete"",""confidence"":0.0034184197429567575}]}",Block,,2024-01-09 12:20:38.065559
|