File size: 2,523 Bytes
0f7e74b
 
 
 
 
 
047d5b0
 
 
 
cc65489
13e77a1
 
cc65489
047d5b0
 
0f7e74b
cc65489
 
 
 
 
 
 
 
 
 
 
 
2a6d2ae
cc65489
 
0f7e74b
047d5b0
 
 
 
5523bc2
cc65489
 
 
 
396ae71
e47de68
cc65489
 
 
 
 
7c61955
e47de68
cc65489
396ae71
7c61955
e47de68
 
 
2a6d2ae
e47de68
13e77a1
cc65489
2a6d2ae
 
396ae71
2a6d2ae
 
0b2af02
516765a
 
 
0b2af02
abb9f88
2a6d2ae
 
396ae71
2a6d2ae
 
cc65489
 
047d5b0
0f7e74b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
from transformers import pipeline
from PIL import Image
from datasets import load_dataset, Image, list_datasets
from PIL import Image

MODELS = [
            "google/vit-base-patch16-224", #Classifição geral
            "nateraw/vit-age-classifier" #Classifição de idade
]
DATASETS = [
            "Nunt/testedata",
            "Nunt/backup_leonardo_2024-02-01" 
]
MAX_N_LABELS = 5


def classify_images(classifier_model, dataset_to_classify):
       
    for image in dataset:
        st("Image classification: ", image['file'])
    '''
        image_path = image['file']
        img = Image.open(image_path)
        st.image(img, caption="Original image", use_column_width=True)
        results = classifier(image_path, top_k=MAX_N_LABELS)
        st.write(results)
        st.write("----")
    '''
    return "done"



def main():
    st.title("Bulk Image Classification")
    st.markdown("This app uses several 🤗 models to classify images stored in 🤗 datasets.")
    st.write("Soon we will have a dataset template")
    

    '''
        Model
    '''
    shosen_model_name = st.selectbox("Select the model to use",  MODELS, index=0)
    if shosen_model_name is not None:
        st.write("You selected", shosen_model_name) 
        
    '''
        Dataset
    '''          
    shosen_dataset_name = st.selectbox("Select the dataset to use",  DATASETS, index=0)
    if shosen_dataset_name is not None:
        st.write("You selected", shosen_dataset_name)
        

           
    '''
        click to classify
        image_object = dataset['pasta'][0]
    '''    
    if shosen_model_name is not None and shosen_dataset_name is not None:
        if st.button("Classify images"):
            st.write("# FLAG 1")
            
            dataset = load_dataset(shosen_dataset_name,"testedata_readme")
            st.write("# FLAG 2")
            
            #image_object = dataset['pasta'][0]
            #image_object = dataset['pasta'][0]["image"]
            #st.image(image_object, caption="Uploaded Image", use_column_width=True)
            #st.image(dataset[0], caption="Uploaded Image", use_column_width=True)
            image_object = dataset['pasta'][0]["image"]
            st.image(image_object, caption="Uploaded Image", use_column_width=True)
            st.write("# FLAG 3")
            
            classifier = pipeline('image-classification', model=shosen_model_name, device=0)
            st.write("# FLAG 4")
    


    

if __name__ == "__main__":
    main()