Update app.py
Browse files
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([
|
| 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 |
|