brainai-spaces commited on
Commit
d4547ab
Β·
verified Β·
1 Parent(s): afbd1bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
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(np.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>The result of running the AI inference on an image.</strong></h4>", unsafe_allow_html=True)
36
  else:
37
  st.image("data/intel_rnb.jpg")
38
- st.write("Click on 'Browse Files' in the sidebar to run inference on an image." )
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μš”", type=("mp4"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("Click on 'Browse Files' in the sidebar to run inference on a video.")
72
 
73
  if source_radio == "WEBCAM":
74
  input = camera_input_live()
75
  uploaded_image = Image.open(input)
76
- uploaded_image_cv = cv2.cvtColor(np.array(uploaded_image), cv2.COLOR_RGB2BGR)
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")