BrainAI-1 commited on
Commit
8c91f99
Β·
verified Β·
1 Parent(s): b30cb56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import streamlit as st
 
 
2
  from utils import object_detection_brainai as odb
3
  object_detection = odb.ObjectDetectionModel()
4
 
@@ -7,24 +9,22 @@ st.set_page_config(
7
  page_icon = ":black_cat:",
8
  layout = "wide")
9
 
 
 
 
10
  st.sidebar.header("메뉴")
11
- source_radio = st.sidebar.radio("μ„ νƒν•˜μ„Έμš”", ["IMAGE", "VIDEO", "GAME"])
12
 
13
- col1, col2 = st.columns([2, 3])
14
  with col1:
15
  st.title(":blue[Object Detection] :black_cat:")
16
  with col2:
17
  if source_radio == "GAME":
18
  if st.button('μƒˆλ‘œμš΄ 객체'):
19
  st.session_state.random_class = object_detection.call_class()
20
- else:
21
- pass
22
-
23
- if "random_class" not in st.session_state:
24
- st.session_state.random_class = object_detection.call_class()
25
 
26
  if source_radio == "IMAGE":
27
- st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ 이미지 νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
28
  st.sidebar.header("이미지 파일 μ—…λ‘œλ“œ")
29
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
30
 
@@ -46,7 +46,6 @@ elif source_radio == "VIDEO":
46
  st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
47
  st.sidebar.header("λΉ„λ””μ˜€ 파일 μ—…λ‘œλ“œ")
48
  input_video = st.sidebar.file_uploader("λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”..", type=("mp4"))
49
- print(input_video)
50
  if input_video is not None:
51
  temp_file = object_detection.play_video(input_video)
52
  st.video(temp_file)
@@ -55,7 +54,7 @@ elif source_radio == "VIDEO":
55
 
56
  elif source_radio == "GAME":
57
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
58
- if input_img:
59
  result_img, detected_object = object_detection.process_image(input_img)
60
  if st.session_state.random_class in detected_object:
61
  st.title(f':{st.session_state.random_class}: μ°ΎμŠ΅λ‹ˆλ‹€!')
@@ -66,4 +65,12 @@ elif source_radio == "GAME":
66
 
67
  else:
68
  st.title(f':{st.session_state.random_class}: μžˆλŠ” 이미지λ₯Ό μ—…λ‘œλ“œ')
 
 
 
 
 
 
 
 
69
 
 
1
  import streamlit as st
2
+ import cv2
3
+ from camera_input_live import camera_input_live
4
  from utils import object_detection_brainai as odb
5
  object_detection = odb.ObjectDetectionModel()
6
 
 
9
  page_icon = ":black_cat:",
10
  layout = "wide")
11
 
12
+ if "random_class" not in st.session_state:
13
+ st.session_state.random_class = object_detection.call_class()
14
+
15
  st.sidebar.header("메뉴")
16
+ source_radio = st.sidebar.radio("μ„ νƒν•˜μ„Έμš”", ["IMAGE", "VIDEO", "GAME", "WEBCAM"])
17
 
18
+ col1, col2 = st.columns([3, 2])
19
  with col1:
20
  st.title(":blue[Object Detection] :black_cat:")
21
  with col2:
22
  if source_radio == "GAME":
23
  if st.button('μƒˆλ‘œμš΄ 객체'):
24
  st.session_state.random_class = object_detection.call_class()
 
 
 
 
 
25
 
26
  if source_radio == "IMAGE":
27
+ st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ 이미지 νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]")
28
  st.sidebar.header("이미지 파일 μ—…λ‘œλ“œ")
29
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
30
 
 
46
  st.write(":green[μ™Όμͺ½ 메뉴 'Browse files' λ²„νŠΌμ„ ν΄λ¦­ν•˜μ—¬ λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜λ©΄ AI 좔둠이 μ‹œμž‘λ©λ‹ˆλ‹€.]" )
47
  st.sidebar.header("λΉ„λ””μ˜€ 파일 μ—…λ‘œλ“œ")
48
  input_video = st.sidebar.file_uploader("λΉ„λ””μ˜€ νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”..", type=("mp4"))
 
49
  if input_video is not None:
50
  temp_file = object_detection.play_video(input_video)
51
  st.video(temp_file)
 
54
 
55
  elif source_radio == "GAME":
56
  input_img = st.sidebar.file_uploader("이미지 νŒŒμΌμ„ μ„ νƒν•˜μ„Έμš”.", type=("jpg", "png"))
57
+ if input_img is not None:
58
  result_img, detected_object = object_detection.process_image(input_img)
59
  if st.session_state.random_class in detected_object:
60
  st.title(f':{st.session_state.random_class}: μ°ΎμŠ΅λ‹ˆλ‹€!')
 
65
 
66
  else:
67
  st.title(f':{st.session_state.random_class}: μžˆλŠ” 이미지λ₯Ό μ—…λ‘œλ“œ')
68
+
69
+ elif source_radio == "WEBCAM":
70
+ input_img = camera_input_live()
71
+ if input_img:
72
+ result = object_detection.process_image(input_img)
73
+ img_plot = result[0].plot()
74
+
75
+ st.image(img_plot, channels = "BGR")
76