ychafiqui commited on
Commit
c6c388a
1 Parent(s): 1d6fc25

added ability to filter images by damaged parts

Browse files
__pycache__/functions.cpython-311.pyc CHANGED
Binary files a/__pycache__/functions.cpython-311.pyc and b/__pycache__/functions.cpython-311.pyc differ
 
app.py CHANGED
@@ -12,14 +12,16 @@ if "reset" not in st.session_state:
12
  st.session_state["reset"] = False
13
 
14
  with st.sidebar:
15
- name = st.text_input("What's your name?", value=st.session_state.get("name", ""))
16
  name = name.strip().lower()
17
  name_error_placeholder = st.empty()
18
 
 
 
19
  if st.button("Start annotation"):
20
  if name:
21
  st.session_state["name"] = name
22
- st.session_state["img"], st.session_state["img_name"] = get_random_image()
23
  st.rerun()
24
  else:
25
  name_error_placeholder.error("Name is required")
@@ -102,7 +104,7 @@ if "name" in st.session_state:
102
  st.session_state["prev_img_name"] = img_name
103
  st.session_state["prev_img"] = img
104
  st.session_state["prev_rotation"] = st.session_state["rotation"]
105
- st.session_state["img"], st.session_state["img_name"] = get_random_image()
106
  st.session_state["rotation"] = 0
107
  st.session_state["reset"] = False
108
  st.rerun()
 
12
  st.session_state["reset"] = False
13
 
14
  with st.sidebar:
15
+ name = st.text_input("Name *", value=st.session_state.get("name", ""))
16
  name = name.strip().lower()
17
  name_error_placeholder = st.empty()
18
 
19
+ parts_filter = st.multiselect("Filter images by damaged parts (optional)", df.columns[6:], help="Select one or more parts to filter the images by.")
20
+
21
  if st.button("Start annotation"):
22
  if name:
23
  st.session_state["name"] = name
24
+ st.session_state["img"], st.session_state["img_name"] = get_random_image(parts_filter)
25
  st.rerun()
26
  else:
27
  name_error_placeholder.error("Name is required")
 
104
  st.session_state["prev_img_name"] = img_name
105
  st.session_state["prev_img"] = img
106
  st.session_state["prev_rotation"] = st.session_state["rotation"]
107
+ st.session_state["img"], st.session_state["img_name"] = get_random_image(parts_filter)
108
  st.session_state["rotation"] = 0
109
  st.session_state["reset"] = False
110
  st.rerun()
custom_style.css CHANGED
@@ -1,5 +1,5 @@
1
  .st-emotion-cache-1jicfl2 {
2
- padding-top: 4rem;
3
  }
4
 
5
  /* .st-emotion-cache-vdokb0 p {
@@ -10,14 +10,14 @@
10
  .st-dc, .st-cx {
11
  margin-top: 5px !important;
12
  }
13
- .st-af {
14
  justify-content: center;
15
  margin-top: 0px;
16
  margin-bottom: 0px;
17
- }
18
  div.row-widget.stRadio > div[role="radiogroup"] > label[data-baseweb="radio"] {
19
  background-color: #f4ca9a;
20
- padding-right: 38px;
21
  padding-left: 30px;
22
  padding-bottom: 6px;
23
  padding-top: 4px;
@@ -26,6 +26,6 @@ div.row-widget.stRadio > div[role="radiogroup"] > label[data-baseweb="radio"] {
26
  div.row-widget.stRadio > div[role="radiogroup"] > label[data-baseweb="radio"]:hover {
27
  background-color: #eb9a68;
28
  }
29
- .st-cj {
30
  background-color: rgb(255, 75, 75);
31
- }
 
1
  .st-emotion-cache-1jicfl2 {
2
+ padding-top: 3.8rem;
3
  }
4
 
5
  /* .st-emotion-cache-vdokb0 p {
 
10
  .st-dc, .st-cx {
11
  margin-top: 5px !important;
12
  }
13
+ /* .st-af {
14
  justify-content: center;
15
  margin-top: 0px;
16
  margin-bottom: 0px;
17
+ } */
18
  div.row-widget.stRadio > div[role="radiogroup"] > label[data-baseweb="radio"] {
19
  background-color: #f4ca9a;
20
+ padding-right: 36px;
21
  padding-left: 30px;
22
  padding-bottom: 6px;
23
  padding-top: 4px;
 
26
  div.row-widget.stRadio > div[role="radiogroup"] > label[data-baseweb="radio"]:hover {
27
  background-color: #eb9a68;
28
  }
29
+ /* .st-cj {
30
  background-color: rgb(255, 75, 75);
31
+ } */
functions.py CHANGED
@@ -20,8 +20,12 @@ with io.BytesIO(response['Body'].read()) as bio:
20
  df = pd.read_csv(bio, low_memory=False)
21
  df = df[df['s3_available'] == True]
22
 
23
- def get_random_image():
24
  not_validated_imgs = df[df["validated"] == False]["img_name"].tolist()
 
 
 
 
25
  if len(not_validated_imgs) == 0:
26
  return None, None
27
  image_name = random.choice(not_validated_imgs)
 
20
  df = pd.read_csv(bio, low_memory=False)
21
  df = df[df['s3_available'] == True]
22
 
23
+ def get_random_image(parts_filter=False):
24
  not_validated_imgs = df[df["validated"] == False]["img_name"].tolist()
25
+ if parts_filter:
26
+ # get rows where all selected parts are damaged (> 0)
27
+ filtered_imgs = df[(df[parts_filter] > 0).all(axis=1)]["img_name"].tolist()
28
+ not_validated_imgs = list(set(not_validated_imgs) & set(filtered_imgs))
29
  if len(not_validated_imgs) == 0:
30
  return None, None
31
  image_name = random.choice(not_validated_imgs)