Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,7 +61,7 @@ _, row1_col1, _ = st.columns([2,3,2])
|
|
| 61 |
_, row2_col1, _ = st.columns([2,3,2])
|
| 62 |
_, row3_col1, row3_col2, row3_col3, row3_col4, _ = st.columns([8,3,3,3,3,8])
|
| 63 |
_, row4_col1, row4_col2, row4_col3, row4_col4, _ = st.columns([8,3,3,3,3,8])
|
| 64 |
-
_, row5_col2, row5_col3, _ = st.columns([1,4,4,1], gap="medium")
|
| 65 |
|
| 66 |
# heading
|
| 67 |
with row0_col1:
|
|
@@ -239,49 +239,30 @@ if st.session_state.screen == 2:
|
|
| 239 |
st.session_state.results = st.session_state.model.predict(st.session_state.tiles, conf=st.session_state.confidence) # predict
|
| 240 |
st.rerun()
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
# st.session_state.detected_characters = {}
|
| 267 |
-
# st.write(str(idx) + str(pred.cls) + str(pred.conf))
|
| 268 |
-
|
| 269 |
-
# if pred.conf >= 0.5:
|
| 270 |
-
# st.write(str(int(pred.cls.item())))
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
# for cls_id in pred:
|
| 274 |
-
# name = class_names[int(cls_id)] # Convert class ID to character name
|
| 275 |
-
|
| 276 |
-
# if name in st.session_state.detected_characters:
|
| 277 |
-
# if conf >= st.session_state.confidence:
|
| 278 |
-
# st.session_state.detected_characters[name].append(idx)
|
| 279 |
-
|
| 280 |
-
# display locations
|
| 281 |
-
# st.session_state.locations = ""
|
| 282 |
-
# for name, idx in st.session_state.detected_characters.items():
|
| 283 |
-
# st.session_state.locations += f" {name} tiles: {str(idx)}, )"
|
| 284 |
-
# st.write(st.session_state.locations)
|
| 285 |
|
| 286 |
# plot predicted image
|
| 287 |
st.markdown(f"<h4 style='text-align: center; color: black;'>Image Tile {str(st.session_state.image_counter + 1)}</h4>", unsafe_allow_html=True)
|
|
|
|
| 61 |
_, row2_col1, _ = st.columns([2,3,2])
|
| 62 |
_, row3_col1, row3_col2, row3_col3, row3_col4, _ = st.columns([8,3,3,3,3,8])
|
| 63 |
_, row4_col1, row4_col2, row4_col3, row4_col4, _ = st.columns([8,3,3,3,3,8])
|
| 64 |
+
_, row5_col2, row5_col3, row5_col4, _ = st.columns([1,4,4,2,1], gap="medium")
|
| 65 |
|
| 66 |
# heading
|
| 67 |
with row0_col1:
|
|
|
|
| 239 |
st.session_state.results = st.session_state.model.predict(st.session_state.tiles, conf=st.session_state.confidence) # predict
|
| 240 |
st.rerun()
|
| 241 |
|
| 242 |
+
with row5_col4:
|
| 243 |
+
# show character locations
|
| 244 |
+
class_names = {0: "Waldo", 1: "Wenda", 2: "Odlaw", 3: "Wizard", 4: "Woof"}
|
| 245 |
+
character_dict = {
|
| 246 |
+
"Waldo": [],
|
| 247 |
+
"Wenda": [],
|
| 248 |
+
"Odlaw": [],
|
| 249 |
+
"Wizard": [],
|
| 250 |
+
"Woof": [],
|
| 251 |
+
}
|
| 252 |
+
for idx, pred in enumerate(st.session_state.results):
|
| 253 |
+
try:
|
| 254 |
+
for boxes in pred.boxes:
|
| 255 |
+
if boxes.conf >= 0.5:
|
| 256 |
+
character_dict[class_names[int(boxes.cls.item())]].append(idx + 1)
|
| 257 |
+
except:
|
| 258 |
+
pass
|
| 259 |
+
|
| 260 |
+
st.session_state.output = ""
|
| 261 |
+
for key, value in character_dict.items():
|
| 262 |
+
if value != []:
|
| 263 |
+
st.session_state.output += str(key) + " tiles: "+ str(value) + " \n"
|
| 264 |
+
|
| 265 |
+
st.write(st.session_state.output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
# plot predicted image
|
| 268 |
st.markdown(f"<h4 style='text-align: center; color: black;'>Image Tile {str(st.session_state.image_counter + 1)}</h4>", unsafe_allow_html=True)
|