JaredBailey commited on
Commit
10961ac
·
verified ·
1 Parent(s): fb3bd02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -237,7 +237,24 @@ if st.session_state.screen == 2:
237
  st.markdown("<p style='text-align: center; color: black;'>This process takes around 30 seconds.</p>", unsafe_allow_html=True)
238
  st.session_state.results = st.session_state.model.predict(st.session_state.tiles, conf=st.session_state.confidence) # predict
239
  st.rerun()
240
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  # plot predicted image
242
  st.markdown(f"<h4 style='text-align: center; color: black;'>Image Tile {str(st.session_state.image_counter + 1)}</h4>", unsafe_allow_html=True)
243
  im_bgr = st.session_state.results[st.session_state.image_counter].plot() # BGR-order numpy array
 
237
  st.markdown("<p style='text-align: center; color: black;'>This process takes around 30 seconds.</p>", unsafe_allow_html=True)
238
  st.session_state.results = st.session_state.model.predict(st.session_state.tiles, conf=st.session_state.confidence) # predict
239
  st.rerun()
240
+
241
+ # show character locations
242
+ class_names = {0: "Waldo", 1: "Wenda", 2: "Odlaw", 3: "Wizard", 4: "Woof"}
243
+ for idx, pred in enumerate(results):
244
+ #extract detected character names and their confidence scores
245
+ st.session_state.detected_characters = {}
246
+ for *_, cls_id, conf in pred:
247
+ name = class_names[int(cls_id)] # Convert class ID to character name
248
+ if name in st.session_state.detected_characters:
249
+ if conf >= st.session_state.confidence:
250
+ st.session_state.detected_characters[name].append(idx)
251
+
252
+ # display locations
253
+ st.session_state.locations = ""
254
+ for name, idx in st.session_state.detected_characters.items():
255
+ st.session_state.locations += f" {name} page: {str(idx)}, )"
256
+ st.write(st.session_state.locations)
257
+
258
  # plot predicted image
259
  st.markdown(f"<h4 style='text-align: center; color: black;'>Image Tile {str(st.session_state.image_counter + 1)}</h4>", unsafe_allow_html=True)
260
  im_bgr = st.session_state.results[st.session_state.image_counter].plot() # BGR-order numpy array