Update app.py
Browse files
app.py
CHANGED
|
@@ -25,17 +25,17 @@ conf_threshold = float(st.sidebar.slider("μ λ’°λ μκ³κ°μ μ ννμΈμ
|
|
| 25 |
input = None
|
| 26 |
if source_radio == "IMAGE":
|
| 27 |
st.sidebar.header("μ΄λ―Έμ§ νμΌ μ
λ‘λ")
|
| 28 |
-
input = st.sidebar.file_uploader("μ΄λ―Έμ§ νμΌμ μ ννμΈμ", type=("jpg", "png"))
|
| 29 |
if input is not None:
|
| 30 |
uploaded_image = Image.open(input)
|
| 31 |
-
uploaded_image_cv = cv2.cvtColor(
|
| 32 |
boxes, resized_image = utils.predict_image(uploaded_image_cv, conf_threshold = conf_threshold)
|
| 33 |
result_image = utils.convert_result_to_image(uploaded_image_cv, resized_image, boxes, conf_labels=False)
|
| 34 |
st.image(result_image, channels = "RGB")
|
| 35 |
-
st.markdown(f"<h4 style='color: blue;'><strong>
|
| 36 |
else:
|
| 37 |
st.image("data/intel_rnb.jpg")
|
| 38 |
-
st.write("
|
| 39 |
|
| 40 |
def play_video(video_source):
|
| 41 |
camera = cv2.VideoCapture(video_source)
|
|
@@ -55,7 +55,25 @@ def play_video(video_source):
|
|
| 55 |
visualized_image = utils.convert_result_to_image(frame, resized_image, boxes, conf_labels=False)
|
| 56 |
except:
|
| 57 |
visualized_image = frame
|
| 58 |
-
st_frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
if input_file is not None:
|
| 60 |
# νμΌμ μμ κ²½λ‘μ μ μ₯
|
| 61 |
g = io.BytesIO(input_file.read())
|
|
@@ -68,12 +86,12 @@ def play_video(video_source):
|
|
| 68 |
play_video(temporary_location)
|
| 69 |
else:
|
| 70 |
st.video("data/sample_video.mp4")
|
| 71 |
-
st.write("
|
| 72 |
|
| 73 |
if source_radio == "WEBCAM":
|
| 74 |
input = camera_input_live()
|
| 75 |
uploaded_image = Image.open(input)
|
| 76 |
-
uploaded_image_cv = cv2.cvtColor(
|
| 77 |
boxes, resized_image = utils.predict_image(uploaded_image_cv, conf_threshold)
|
| 78 |
visualized_image = utils.convert_result_to_image(uploaded_image_cv, resized_image, boxes, conf_labels=False)
|
| 79 |
st.image(visualized_image, channels = "RGB")
|
|
|
|
| 25 |
input = None
|
| 26 |
if source_radio == "IMAGE":
|
| 27 |
st.sidebar.header("μ΄λ―Έμ§ νμΌ μ
λ‘λ")
|
| 28 |
+
input = st.sidebar.file_uploader("μ΄λ―Έμ§ νμΌμ μ ννμΈμ.", type=("jpg", "png"))
|
| 29 |
if input is not None:
|
| 30 |
uploaded_image = Image.open(input)
|
| 31 |
+
uploaded_image_cv = cv2.cvtColor(numpy.array(uploaded_image), cv2.COLOR_RGB2BGR)
|
| 32 |
boxes, resized_image = utils.predict_image(uploaded_image_cv, conf_threshold = conf_threshold)
|
| 33 |
result_image = utils.convert_result_to_image(uploaded_image_cv, resized_image, boxes, conf_labels=False)
|
| 34 |
st.image(result_image, channels = "RGB")
|
| 35 |
+
st.markdown(f"<h4 style='color: blue;'><strong>μ΄λ―Έμ§μμ AI μΆλ‘ μ μ€νν κ²°κ³Ό μ
λλ€.</strong></h4>", unsafe_allow_html=True)
|
| 36 |
else:
|
| 37 |
st.image("data/intel_rnb.jpg")
|
| 38 |
+
st.write("'Browse Files' λ²νΌμ ν΄λ¦νμ¬ μ΄λ―Έμ§μμ AI μΆλ‘ μ μμν©λλ€." )
|
| 39 |
|
| 40 |
def play_video(video_source):
|
| 41 |
camera = cv2.VideoCapture(video_source)
|
|
|
|
| 55 |
visualized_image = utils.convert_result_to_image(frame, resized_image, boxes, conf_labels=False)
|
| 56 |
except:
|
| 57 |
visualized_image = frame
|
| 58 |
+
st_frame.image(visualized_image, channels = "BGR")
|
| 59 |
+
video_row.append(cv2.cvtColor(visualized_image,cv2.COLOR_BGR2RGB))
|
| 60 |
+
frame_count +=1
|
| 61 |
+
progress_bar.progress(frame_count/total_frames, text=None)
|
| 62 |
+
|
| 63 |
+
else:
|
| 64 |
+
progress_bar.empty()
|
| 65 |
+
camera.release()
|
| 66 |
+
st_frame.empty()
|
| 67 |
+
break
|
| 68 |
+
clip = mpy.ImageSequenceClip(video_row, fps = fps)
|
| 69 |
+
clip.write_videofile(temp_file_2.name)
|
| 70 |
+
st.video(temp_file_2.name)
|
| 71 |
+
|
| 72 |
+
# νμΌ μ
λ‘λ μ²λ¦¬
|
| 73 |
+
temporary_location = None
|
| 74 |
+
if source_radio == "VIDEO":
|
| 75 |
+
st.sidebar.header("λΉλμ€ νμΌ μ
λ‘λ")
|
| 76 |
+
input_file = st.sidebar.file_uploader("λΉλμ€ νμΌμ μ ννμΈμ.", type=("mp4"))
|
| 77 |
if input_file is not None:
|
| 78 |
# νμΌμ μμ κ²½λ‘μ μ μ₯
|
| 79 |
g = io.BytesIO(input_file.read())
|
|
|
|
| 86 |
play_video(temporary_location)
|
| 87 |
else:
|
| 88 |
st.video("data/sample_video.mp4")
|
| 89 |
+
st.write("'Browse Files' λ²νΌμ ν΄λ¦νμ¬ μμμμ AI μΆλ‘ μ μμν©λλ€.")
|
| 90 |
|
| 91 |
if source_radio == "WEBCAM":
|
| 92 |
input = camera_input_live()
|
| 93 |
uploaded_image = Image.open(input)
|
| 94 |
+
uploaded_image_cv = cv2.cvtColor(numpy.array(uploaded_image), cv2.COLOR_RGB2BGR)
|
| 95 |
boxes, resized_image = utils.predict_image(uploaded_image_cv, conf_threshold)
|
| 96 |
visualized_image = utils.convert_result_to_image(uploaded_image_cv, resized_image, boxes, conf_labels=False)
|
| 97 |
st.image(visualized_image, channels = "RGB")
|