Spaces:
Sleeping
Sleeping
Merge branch 'feature/loop_dataset'
Browse files- app.py +25 -67
- hf_bulk_image_classifier.code-workspace +29 -0
app.py
CHANGED
|
@@ -16,85 +16,47 @@ MAX_N_LABELS = 5
|
|
| 16 |
SPLIT_TO_CLASSIFY = 'pasta'
|
| 17 |
|
| 18 |
COLS = st.columns([0.75, 0.25])
|
| 19 |
-
#SCROLLABLE_TEXT = COLS[1].text_area("Conteúdo da segunda coluna", height=500)
|
| 20 |
SCROLLABLE_TEXT = COLS[1].container(height=500)
|
| 21 |
|
| 22 |
|
| 23 |
-
|
| 24 |
-
def classify_one_image(classifier_model, dataset_to_classify):
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
#image_object = dataset[SPLIT_TO_CLASSIFY][i]["image"]
|
| 29 |
-
#st.image(image_object, caption="Uploaded Image", width=300)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
#for i in range(len(dataset_to_classify)):
|
| 33 |
-
#for image in dataset_to_classify:
|
| 34 |
-
#image_object = dataset[SPLIT_TO_CLASSIFY][i]["image"]
|
| 35 |
-
#st.image(image_object, caption="Uploaded Image", width=300)
|
| 36 |
-
|
| 37 |
-
#st.write(f"Image classification: ", image['file'])
|
| 38 |
-
|
| 39 |
-
# image_path = image['file']
|
| 40 |
-
# img = Image.open(image_path)
|
| 41 |
-
# st.image(img, caption="Original image", use_column_width=True)
|
| 42 |
-
# results = classifier(image_path, top_k=MAX_N_LABELS)
|
| 43 |
-
# st.write(results)
|
| 44 |
-
# st.write("----")
|
| 45 |
-
|
| 46 |
-
return "done"
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
def classify_full_dataset(shosen_dataset_name, chosen_model_name):
|
| 51 |
image_count = 0
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
#dataset
|
| 54 |
-
dataset = load_dataset(shosen_dataset_name,"testedata_readme")
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
#Image teste load
|
| 57 |
-
image_object = dataset['pasta'][0]["image"]
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
#modle instance
|
| 63 |
-
classifier_pipeline = pipeline('image-classification', model=chosen_model_name)
|
| 64 |
-
#COLS[1].write("### FLAG 4")
|
| 65 |
-
|
| 66 |
-
#classification
|
| 67 |
-
classification_result = classifier_pipeline(image_object)
|
| 68 |
-
SCROLLABLE_TEXT.write(classification_result)
|
| 69 |
-
#COLS[1].write("### FLAG 5")
|
| 70 |
-
#classification_array.append(classification_result)
|
| 71 |
|
| 72 |
-
#save classification
|
| 73 |
|
| 74 |
-
image_count += 1
|
| 75 |
-
SCROLLABLE_TEXT.write("Image count")
|
| 76 |
-
SCROLLABLE_TEXT.write(image_count)
|
| 77 |
-
return image_count
|
| 78 |
-
|
| 79 |
|
| 80 |
-
def make_template():
|
| 81 |
|
| 82 |
-
tile = CONTAINER_TOP.title(":balloon:")
|
| 83 |
-
tile.title(":balloon:")
|
| 84 |
|
| 85 |
-
|
| 86 |
-
CONTAINER_TOP.title("titulo de teste dentro do container CONTAINER_TOP")
|
| 87 |
-
with CONTAINER_BODY:
|
| 88 |
-
#COL1, COL2 = st.columns([3, 1])
|
| 89 |
-
with COLS[1]:
|
| 90 |
-
CONTAINER_LOOP.write("### OUTPUT")
|
| 91 |
|
| 92 |
|
| 93 |
def main():
|
| 94 |
-
|
| 95 |
|
| 96 |
COLS[0].write("# Bulk Image Classification App")
|
| 97 |
-
|
| 98 |
|
| 99 |
#with CONTAINER_BODY:
|
| 100 |
with COLS[0]:
|
|
@@ -114,17 +76,13 @@ def main():
|
|
| 114 |
COLS[0].write(shosen_dataset_name)
|
| 115 |
|
| 116 |
#click to classify
|
| 117 |
-
#image_object = dataset['pasta'][0]
|
| 118 |
if chosen_model_name is not None and shosen_dataset_name is not None:
|
| 119 |
if COLS[0].button("Classify images"):
|
| 120 |
|
| 121 |
-
|
| 122 |
-
classification_result = classify_full_dataset(shosen_dataset_name, chosen_model_name)
|
| 123 |
COLS[0].write("Classification result {classification_result}")
|
| 124 |
COLS[0].write(classification_result)
|
| 125 |
-
|
| 126 |
-
#st.write("# FLAG 6")
|
| 127 |
-
#st.write(classification_array)
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
main()
|
|
|
|
| 16 |
SPLIT_TO_CLASSIFY = 'pasta'
|
| 17 |
|
| 18 |
COLS = st.columns([0.75, 0.25])
|
|
|
|
| 19 |
SCROLLABLE_TEXT = COLS[1].container(height=500)
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def classify_full_dataset(shosen_dataset_name, chosen_model_name):
|
| 23 |
image_count = 0
|
| 24 |
|
| 25 |
+
#modle instance
|
| 26 |
+
classifier_pipeline = pipeline('image-classification', model=chosen_model_name)
|
| 27 |
+
|
| 28 |
#dataset
|
| 29 |
+
dataset = load_dataset(shosen_dataset_name,"testedata_readme")
|
| 30 |
+
|
| 31 |
+
for i in range(len(dataset)):
|
| 32 |
+
SCROLLABLE_TEXT.write("i-1:" + str(i-1))
|
| 33 |
+
image_object = dataset['pasta'][i-1]["image"]
|
| 34 |
+
SCROLLABLE_TEXT.image(image_object, caption="Uploaded Image", width=300)
|
| 35 |
+
#classification
|
| 36 |
+
classification_result = classifier_pipeline(image_object)
|
| 37 |
+
SCROLLABLE_TEXT.write(classification_result)
|
| 38 |
+
#TODO save classification result in dataset
|
| 39 |
+
image_count += 1
|
| 40 |
+
SCROLLABLE_TEXT.write(f"Image count" + str(image_count))
|
| 41 |
+
#SCROLLABLE_TEXT.write(image_count)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
#Image teste load
|
| 45 |
+
#image_object = dataset['pasta'][0]["image"]
|
| 46 |
+
#SCROLLABLE_TEXT.image(image_object, caption="Uploaded Image", width=300)
|
| 47 |
+
|
| 48 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
|
|
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
|
|
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def main():
|
|
|
|
| 58 |
|
| 59 |
COLS[0].write("# Bulk Image Classification App")
|
|
|
|
| 60 |
|
| 61 |
#with CONTAINER_BODY:
|
| 62 |
with COLS[0]:
|
|
|
|
| 76 |
COLS[0].write(shosen_dataset_name)
|
| 77 |
|
| 78 |
#click to classify
|
|
|
|
| 79 |
if chosen_model_name is not None and shosen_dataset_name is not None:
|
| 80 |
if COLS[0].button("Classify images"):
|
| 81 |
|
| 82 |
+
classify_full_dataset(shosen_dataset_name, chosen_model_name)
|
|
|
|
| 83 |
COLS[0].write("Classification result {classification_result}")
|
| 84 |
COLS[0].write(classification_result)
|
| 85 |
+
|
|
|
|
|
|
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
| 88 |
main()
|
hf_bulk_image_classifier.code-workspace
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"folders": [
|
| 3 |
+
{
|
| 4 |
+
"path": "."
|
| 5 |
+
}
|
| 6 |
+
],
|
| 7 |
+
"settings": {
|
| 8 |
+
"workbench.colorCustomizations": {
|
| 9 |
+
"activityBar.activeBackground": "#fa1b49",
|
| 10 |
+
"activityBar.background": "#fa1b49",
|
| 11 |
+
"activityBar.foreground": "#e7e7e7",
|
| 12 |
+
"activityBar.inactiveForeground": "#e7e7e799",
|
| 13 |
+
"activityBarBadge.background": "#155e02",
|
| 14 |
+
"activityBarBadge.foreground": "#e7e7e7",
|
| 15 |
+
"commandCenter.border": "#e7e7e799",
|
| 16 |
+
"sash.hoverBorder": "#fa1b49",
|
| 17 |
+
"statusBar.background": "#dd0531",
|
| 18 |
+
"statusBar.foreground": "#e7e7e7",
|
| 19 |
+
"statusBarItem.hoverBackground": "#fa1b49",
|
| 20 |
+
"statusBarItem.remoteBackground": "#dd0531",
|
| 21 |
+
"statusBarItem.remoteForeground": "#e7e7e7",
|
| 22 |
+
"titleBar.activeBackground": "#dd0531",
|
| 23 |
+
"titleBar.activeForeground": "#e7e7e7",
|
| 24 |
+
"titleBar.inactiveBackground": "#dd053199",
|
| 25 |
+
"titleBar.inactiveForeground": "#e7e7e799"
|
| 26 |
+
},
|
| 27 |
+
"peacock.color": "#dd0531"
|
| 28 |
+
}
|
| 29 |
+
}
|