Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	no message
Browse files- app.py +14 -59
 - hf_bulk_image_classifier.code-workspace +29 -0
 
    	
        app.py
    CHANGED
    
    | 
         @@ -16,85 +16,44 @@ 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 | 
         
             
                SCROLLABLE_TEXT.image(image_object, caption="Uploaded Image", width=300)
         
     | 
| 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 | 
         
            -
             
     | 
| 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 | 
         
            -
                with CONTAINER_FULL:
         
     | 
| 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 +73,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 | 
         
            +
                 
         
     | 
| 26 | 
         
            +
                 
         
     | 
| 27 | 
         
            +
                for i in range(len(dataset)):
         
     | 
| 28 | 
         
            +
                    image_object = dataset['pasta'][i]["image"]
         
     | 
| 29 | 
         
            +
                    SCROLLABLE_TEXT.image(image_object, caption="Uploaded Image", width=300)
         
     | 
| 30 | 
         
            +
                    
         
     | 
| 31 | 
         
            +
                 
         
     | 
| 32 | 
         
            +
                 
         
     | 
| 33 | 
         
             
                #dataset
         
     | 
| 34 | 
         
             
                dataset = load_dataset(shosen_dataset_name,"testedata_readme")
         
     | 
| 35 | 
         
            +
             
         
     | 
| 36 | 
         
             
                #Image teste load 
         
     | 
| 37 | 
         
             
                image_object = dataset['pasta'][0]["image"]
         
     | 
| 
         | 
|
| 38 | 
         
             
                SCROLLABLE_TEXT.image(image_object, caption="Uploaded Image", width=300)
         
     | 
| 39 | 
         
            +
             
     | 
| 
         | 
|
| 40 | 
         
             
                #modle instance
         
     | 
| 41 | 
         
             
                classifier_pipeline = pipeline('image-classification', model=chosen_model_name)
         
     | 
| 
         | 
|
| 42 | 
         | 
| 43 | 
         
             
                #classification
         
     | 
| 44 | 
         
             
                classification_result = classifier_pipeline(image_object)
         
     | 
| 45 | 
         
             
                SCROLLABLE_TEXT.write(classification_result)
         
     | 
| 46 | 
         
            +
             
     | 
| 
         | 
|
| 47 | 
         | 
| 48 | 
         
            +
                #TODO save classification
         
     | 
| 49 | 
         | 
| 50 | 
         
             
                image_count += 1
         
     | 
| 51 | 
         
             
                SCROLLABLE_TEXT.write("Image count")
         
     | 
| 52 | 
         
             
                SCROLLABLE_TEXT.write(image_count)  
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 53 | 
         | 
| 54 | 
         
             
            def main():
         
     | 
| 
         | 
|
| 55 | 
         | 
| 56 | 
         
             
                COLS[0].write("# Bulk Image Classification App")
         
     | 
| 
         | 
|
| 57 | 
         | 
| 58 | 
         
             
                #with CONTAINER_BODY:
         
     | 
| 59 | 
         
             
                with COLS[0]:
         
     | 
| 
         | 
|
| 73 | 
         
             
                    COLS[0].write(shosen_dataset_name)
         
     | 
| 74 | 
         | 
| 75 | 
         
             
                #click to classify
         
     | 
| 
         | 
|
| 76 | 
         
             
                if chosen_model_name is not None and shosen_dataset_name is not None:
         
     | 
| 77 | 
         
             
                    if COLS[0].button("Classify images"):
         
     | 
| 78 | 
         | 
| 79 | 
         
            +
                        classify_full_dataset(shosen_dataset_name, chosen_model_name)
         
     | 
| 
         | 
|
| 80 | 
         
             
                        COLS[0].write("Classification result {classification_result}")
         
     | 
| 81 | 
         
             
                        COLS[0].write(classification_result)
         
     | 
| 82 | 
         
            +
             
         
     | 
| 
         | 
|
| 
         | 
|
| 83 | 
         | 
| 84 | 
         
             
            if __name__ == "__main__":
         
     | 
| 85 | 
         
             
                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 | 
         
            +
            }
         
     |