Nuno-Tome commited on
Commit
78895ec
·
1 Parent(s): a587147

created template

Browse files
Files changed (1) hide show
  1. app.py +46 -38
app.py CHANGED
@@ -14,10 +14,14 @@ DATASETS = [
14
  ]
15
  MAX_N_LABELS = 5
16
  SPLIT_TO_CLASSIFY = 'pasta'
17
- COL1, COL2 = st.columns([3, 1])
18
- CONTAINER_TOP = st.container()
19
- CONTAINER_BODY = st.container()
20
 
 
 
 
 
 
 
 
21
 
22
 
23
 
@@ -55,7 +59,7 @@ def classify_full_dataset(shosen_dataset_name, chosen_model_name):
55
 
56
  #dataset
57
  dataset = load_dataset(shosen_dataset_name,"testedata_readme")
58
- with COL2:
59
  #Image teste load
60
  image_object = dataset['pasta'][0]["image"]
61
  st.image(image_object, caption="Uploaded Image", width=300)
@@ -63,35 +67,41 @@ def classify_full_dataset(shosen_dataset_name, chosen_model_name):
63
 
64
  #modle instance
65
  classifier_pipeline = pipeline('image-classification', model=chosen_model_name)
66
- st.write("### FLAG 4")
67
 
68
  #classification
69
  classification_result = classifier_pipeline(image_object)
70
- st.write(classification_result)
71
- st.write("### FLAG 5")
72
  #classification_array.append(classification_result)
73
 
74
  #save classification
75
 
76
  image_count += 1
 
77
 
78
  return image_count
79
 
 
80
  def make_template():
81
- #st.write("### FLAG 1")
82
- #st.write("### FLAG 2")
83
- pass
 
 
 
 
 
 
84
 
85
  def main():
86
 
87
  make_template()
88
 
89
- with CONTAINER_TOP:
90
- st.title("Bulk Image Classification DEMO")
91
- #CONTAINER_TOP.title("Bulk Image Classification DEMO")
92
-
93
 
94
- # Restart or reset your app
95
  # if st.button("Restart"):
96
  # # Code to restart or reset your app goes here
97
  # import subprocess
@@ -103,29 +113,27 @@ def main():
103
  st.markdown("This app uses several 🤗 models to classify images stored in 🤗 datasets.")
104
  st.write("Soon we will have a dataset template")
105
 
106
-
107
-
108
- #Model
109
- chosen_model_name = st.selectbox("Select the model to use", MODELS, index=0)
110
- if chosen_model_name is not None:
111
- st.write("You selected", chosen_model_name)
112
-
113
- #Dataset
114
- shosen_dataset_name = st.selectbox("Select the dataset to use", DATASETS, index=0)
115
- if shosen_dataset_name is not None:
116
- st.write("You selected", shosen_dataset_name)
117
-
118
- #click to classify
119
- #image_object = dataset['pasta'][0]
120
- if chosen_model_name is not None and shosen_dataset_name is not None:
121
- if st.button("Classify images"):
122
-
123
- #classification_array =[]
124
- classification_result = classify_full_dataset(shosen_dataset_name, chosen_model_name)
125
- st.write(f"Classification result: {classification_result}")
126
- #classification_array.append(classification_result)
127
- #st.write("# FLAG 6")
128
- #st.write(classification_array)
129
 
130
  if __name__ == "__main__":
131
  main()
 
14
  ]
15
  MAX_N_LABELS = 5
16
  SPLIT_TO_CLASSIFY = 'pasta'
 
 
 
17
 
18
+ # COL1, COL2 = st.columns([3, 1])
19
+ # CONTAINER_TOP = st.container()
20
+ # CONTAINER_BODY = st.container()
21
+ # CONTAINER_FULL = st.container()
22
+ # CONTAINER_LOOP = st.container()
23
+ COL1, COL2
24
+ CONTAINER_TOP, CONTAINER_BODY, CONTAINER_FULL, CONTAINER_LOOP
25
 
26
 
27
 
 
59
 
60
  #dataset
61
  dataset = load_dataset(shosen_dataset_name,"testedata_readme")
62
+ with CONTAINER_LOOP:
63
  #Image teste load
64
  image_object = dataset['pasta'][0]["image"]
65
  st.image(image_object, caption="Uploaded Image", width=300)
 
67
 
68
  #modle instance
69
  classifier_pipeline = pipeline('image-classification', model=chosen_model_name)
70
+ CONTAINER_LOOP.write("### FLAG 4")
71
 
72
  #classification
73
  classification_result = classifier_pipeline(image_object)
74
+ CONTAINER_LOOP.write(classification_result)
75
+ CONTAINER_LOOP.write("### FLAG 5")
76
  #classification_array.append(classification_result)
77
 
78
  #save classification
79
 
80
  image_count += 1
81
+ CONTAINER_LOOP.write(f"Image count: {image_count}")
82
 
83
  return image_count
84
 
85
+
86
  def make_template():
87
+ CONTAINER_FULL = st.container()
88
+ with CONTAINER_FULL:
89
+ CONTAINER_TOP = st.container()
90
+ CONTAINER_BODY = st.container()
91
+ with CONTAINER_BODY:
92
+ COL1, COL2 = st.columns([3, 1])
93
+ with COL2:
94
+ CONTAINER_LOOP = st.container()
95
+
96
 
97
  def main():
98
 
99
  make_template()
100
 
101
+ CONTAINER_TOP.title("Bulk Image Classification DEMO")
102
+
 
 
103
 
104
+ # TODO Restart or reset your app
105
  # if st.button("Restart"):
106
  # # Code to restart or reset your app goes here
107
  # import subprocess
 
113
  st.markdown("This app uses several 🤗 models to classify images stored in 🤗 datasets.")
114
  st.write("Soon we will have a dataset template")
115
 
116
+ #Model
117
+ chosen_model_name = st.selectbox("Select the model to use", MODELS, index=0)
118
+ if chosen_model_name is not None:
119
+ COL1.st.write("You selected", chosen_model_name)
120
+
121
+ #Dataset
122
+ shosen_dataset_name = st.selectbox("Select the dataset to use", DATASETS, index=0)
123
+ if shosen_dataset_name is not None:
124
+ COL1.st.write("You selected", shosen_dataset_name)
125
+
126
+ #click to classify
127
+ #image_object = dataset['pasta'][0]
128
+ if chosen_model_name is not None and shosen_dataset_name is not None:
129
+ if COL1.button("Classify images"):
130
+
131
+ #classification_array =[]
132
+ classification_result = classify_full_dataset(shosen_dataset_name, chosen_model_name)
133
+ CONTAINER_LOOP.write(f"Classification result: {classification_result}")
134
+ #classification_array.append(classification_result)
135
+ #st.write("# FLAG 6")
136
+ #st.write(classification_array)
 
 
137
 
138
  if __name__ == "__main__":
139
  main()