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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -29
app.py CHANGED
@@ -1,53 +1,75 @@
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}")
 
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
+ st.write('initialize')
17
 
18
+ if source_radio == "IMAGE":
19
+ st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ 이미지 νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
20
+ st.sidebar.header("이미지 파일 μ—…λ‘œλ“œ")
21
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
 
22
 
23
+ if input_img is not None:
24
+ result_img, detected_object = object_detection.process_image(input_img)
25
+ col1, col2 = st.columns(2)
26
+ with col1:
27
+ st.image(result_img)
28
+ with col2:
29
+ st.header(detected_object)
30
+ else:
31
+ col1, col2 = st.columns(2)
32
+ with col1:
33
+ st.image("data/table.jpg")
34
+ with col2:
35
+ st.header("Objects detected: chair, potted plant, vase, dining table")
36
+
37
+ elif source_radio == "VIDEO":
38
+ st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
39
+ st.sidebar.header("λΉ„λ””μ˜€ 파일 μ—…λ‘œλ“œ")
40
+ input_video = st.sidebar.file_uploader("λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”..", type=("mp4"))
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
  with col1:
55
+ st.title(f':{st.session_state.random_class}: μžˆλŠ” 이미지λ₯Ό μ—…λ‘œλ“œ') # Display the header
56
+
57
+ with col2:
58
+ if st.button('μƒˆλ‘œμš΄ 객체'):
59
+ st.session_state.random_class = object_detection.call_class()
60
  else:
61
  result_img, detected_object = object_detection.process_image(input_img)
 
62
 
63
  with col1:
64
+
65
+ if st.session_state.random_class in detected_object:
66
  st.header(f':{st.session_state.random_class}: μ°ΎμŠ΅λ‹ˆλ‹€!')
67
+
68
  else:
69
  st.header(f':{st.session_state.random_class}: 찾을 수 μ—†μŠ΅λ‹ˆλ‹€')
70
+ st.image(result_img)
71
+
72
+ with col2:
73
+ if st.button('μƒˆλ‘œμš΄ 객체'):
74
+ st.session_state.random_class = object_detection.call_class()
75
+ st.write("new object")