BrainAI-1 commited on
Commit
2f179c2
Β·
verified Β·
1 Parent(s): 7456c22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -56
app.py CHANGED
@@ -1,82 +1,53 @@
1
  import streamlit as st
2
- import cv2
3
  from utils import object_detection_brainai as odb
 
 
 
 
4
  object_detection = odb.ObjectDetectionModel()
5
 
6
  st.set_page_config(
7
- page_title = "객체 인식",
8
- page_icon = ":black_cat:",
9
- layout = "wide")
 
10
 
11
  st.title(":blue[Object Detection] :black_cat:")
12
  st.sidebar.header("메뉴")
13
  source_radio = st.sidebar.radio("μ„ νƒν•˜μ„Έμš”", ["IMAGE", "VIDEO", "GAME"])
 
 
14
  if 'random_class' not in st.session_state:
15
  st.session_state.random_class = object_detection.call_class()
 
16
 
17
- if source_radio == "IMAGE":
18
- st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ 이미지 νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
19
- st.sidebar.header("이미지 파일 μ—…λ‘œλ“œ")
20
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
 
21
 
22
- if input_img is not None:
23
- result_img, detected_object = object_detection.process_image(input_img)
24
- col1, col2 = st.columns(2)
25
- with col1:
26
- st.image(result_img)
27
- with col2:
28
- st.header(detected_object)
29
- else:
30
- col1, col2 = st.columns(2)
31
- with col1:
32
- st.image("data/table.jpg")
33
- with col2:
34
- st.header("Objects detected: chair, potted plant, vase, dining table")
35
-
36
- elif source_radio == "VIDEO":
37
- st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
38
- st.sidebar.header("λΉ„λ””μ˜€ 파일 μ—…λ‘œλ“œ")
39
- input_video = st.sidebar.file_uploader("λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”..", type=("mp4"))
40
- print(input_video)
41
- if input_video is not None:
42
- temp_file = object_detection.play_video(input_video)
43
- st.video(temp_file)
44
- else:
45
- st.video("data/breakfast.mp4")
46
-
47
 
48
- elif source_radio == "GAME":
49
- input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
50
- col1, col2 = st.columns([3, 1]) # Adjust the column widths as needed
51
  if input_img is None:
52
-
53
-
54
-
55
  with col1:
56
- st.title(f':{st.session_state.random_class}: μžˆλŠ” 이미지λ₯Ό μ—…λ‘œλ“œ') # Display the header
57
-
58
- with col2:
59
- if st.button('μƒˆλ‘œμš΄ 객체'):
60
- st.session_state.random_class = object_detection.call_class()
61
  else:
62
  result_img, detected_object = object_detection.process_image(input_img)
63
-
64
-
65
-
66
 
67
  with col1:
68
-
69
- if st.session_state.random_class in detected_object:
70
  st.header(f':{st.session_state.random_class}: μ°ΎμŠ΅λ‹ˆλ‹€!')
71
-
72
  else:
73
  st.header(f':{st.session_state.random_class}: 찾을 수 μ—†μŠ΅λ‹ˆλ‹€')
74
- st.image(result_img)
75
-
76
- with col2:
77
- if st.button('μƒˆλ‘œμš΄ 객체'):
78
- st.session_state.random_class = object_detection.call_class()
79
-
80
 
 
81
 
82
-
 
 
 
 
 
1
  import streamlit as st
2
+ import logging
3
  from utils import object_detection_brainai as odb
4
+
5
+ # Setup logging
6
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
7
+
8
  object_detection = odb.ObjectDetectionModel()
9
 
10
  st.set_page_config(
11
+ page_title="객체 인식",
12
+ page_icon=":black_cat:",
13
+ layout="wide"
14
+ )
15
 
16
  st.title(":blue[Object Detection] :black_cat:")
17
  st.sidebar.header("메뉴")
18
  source_radio = st.sidebar.radio("μ„ νƒν•˜μ„Έμš”", ["IMAGE", "VIDEO", "GAME"])
19
+
20
+ # Track when the random class is assigned
21
  if 'random_class' not in st.session_state:
22
  st.session_state.random_class = object_detection.call_class()
23
+ logging.info(f"Initialized random_class: {st.session_state.random_class}")
24
 
25
+ elif source_radio == "GAME":
 
 
26
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
27
+ col1, col2 = st.columns([3, 1])
28
 
29
+ logging.info(f"Current random_class: {st.session_state.random_class}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
 
 
 
31
  if input_img is None:
 
 
 
32
  with col1:
33
+ st.title(f':{st.session_state.random_class}: μžˆλŠ” 이미지λ₯Ό μ—…λ‘œλ“œ')
34
+
 
 
 
35
  else:
36
  result_img, detected_object = object_detection.process_image(input_img)
37
+ logging.info(f"Detected objects: {detected_object}")
 
 
38
 
39
  with col1:
40
+ if st.session_state.random_class in detected_object:
 
41
  st.header(f':{st.session_state.random_class}: μ°ΎμŠ΅λ‹ˆλ‹€!')
42
+ logging.info(f"Correct object {st.session_state.random_class} found!")
43
  else:
44
  st.header(f':{st.session_state.random_class}: 찾을 수 μ—†μŠ΅λ‹ˆλ‹€')
45
+ logging.info(f"Object {st.session_state.random_class} NOT found!")
 
 
 
 
 
46
 
47
+ st.image(result_img)
48
 
49
+ with col2:
50
+ if st.button('μƒˆλ‘œμš΄ 객체'):
51
+ old_class = st.session_state.random_class
52
+ st.session_state.random_class = object_detection.call_class()
53
+ logging.info(f"Random class changed from {old_class} to {st.session_state.random_class}")