Update app.py
Browse files
app.py
CHANGED
|
@@ -9,17 +9,6 @@ st.set_page_config(page_title="Ruang Belajar", layout="wide", initial_sidebar_st
|
|
| 9 |
|
| 10 |
st.title('Ruang Belajar Deployment YoloV9')
|
| 11 |
|
| 12 |
-
# Membuat Sidebar
|
| 13 |
-
with st.sidebar:
|
| 14 |
-
|
| 15 |
-
video = st.radio('Pilih data video', ['Webcam', 'YouTube'])
|
| 16 |
-
link_youtube = ""
|
| 17 |
-
if video == 'YouTube':
|
| 18 |
-
link_youtube = st.text_input('Masukan Link Youtube', '')
|
| 19 |
-
|
| 20 |
-
st.sidebar.image("logo.png", use_column_width=True)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
# Load Model YOLOv9
|
| 24 |
model = YOLO('yolov9c.pt')
|
| 25 |
|
|
@@ -36,14 +25,12 @@ def plot_boxes(frame, model):
|
|
| 36 |
return annotasi.result()
|
| 37 |
|
| 38 |
# Membuat Function untuk process dan display video
|
| 39 |
-
def process_video(data, model):
|
| 40 |
if data == 'Webcam':
|
| 41 |
camera = cv2.VideoCapture(0) # kode webcam
|
| 42 |
else: # YouTube link
|
| 43 |
camera = CamGear(source=data, stream_mode=True, logging=True).start()
|
| 44 |
|
| 45 |
-
FRAME_WINDOW = st.empty()
|
| 46 |
-
|
| 47 |
while True:
|
| 48 |
if data == 'Webcam':
|
| 49 |
ret, frame = camera.read()
|
|
@@ -56,14 +43,27 @@ def process_video(data, model):
|
|
| 56 |
|
| 57 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 58 |
frame = plot_boxes(frame, model)
|
| 59 |
-
|
| 60 |
|
| 61 |
if data == 'Webcam':
|
| 62 |
camera.release()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
with st.sidebar:
|
| 64 |
-
# Process video
|
| 65 |
if st.button('Start'):
|
| 66 |
if video == 'YouTube' and link_youtube:
|
| 67 |
-
process_video(link_youtube, model)
|
| 68 |
elif video == 'Webcam':
|
| 69 |
-
process_video('Webcam', model)
|
|
|
|
| 9 |
|
| 10 |
st.title('Ruang Belajar Deployment YoloV9')
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Load Model YOLOv9
|
| 13 |
model = YOLO('yolov9c.pt')
|
| 14 |
|
|
|
|
| 25 |
return annotasi.result()
|
| 26 |
|
| 27 |
# Membuat Function untuk process dan display video
|
| 28 |
+
def process_video(data, model, placeholder):
|
| 29 |
if data == 'Webcam':
|
| 30 |
camera = cv2.VideoCapture(0) # kode webcam
|
| 31 |
else: # YouTube link
|
| 32 |
camera = CamGear(source=data, stream_mode=True, logging=True).start()
|
| 33 |
|
|
|
|
|
|
|
| 34 |
while True:
|
| 35 |
if data == 'Webcam':
|
| 36 |
ret, frame = camera.read()
|
|
|
|
| 43 |
|
| 44 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 45 |
frame = plot_boxes(frame, model)
|
| 46 |
+
placeholder.image(frame)
|
| 47 |
|
| 48 |
if data == 'Webcam':
|
| 49 |
camera.release()
|
| 50 |
+
|
| 51 |
+
# Sidebar
|
| 52 |
+
with st.sidebar:
|
| 53 |
+
video = st.radio('Pilih data video', ['Webcam', 'YouTube'])
|
| 54 |
+
link_youtube = ""
|
| 55 |
+
if video == 'YouTube':
|
| 56 |
+
link_youtube = st.text_input('Masukan Link Youtube', '')
|
| 57 |
+
|
| 58 |
+
st.image("logo.png", use_column_width=True)
|
| 59 |
+
|
| 60 |
+
# Main area
|
| 61 |
+
process_placeholder = st.empty()
|
| 62 |
+
|
| 63 |
+
# Process video
|
| 64 |
with st.sidebar:
|
|
|
|
| 65 |
if st.button('Start'):
|
| 66 |
if video == 'YouTube' and link_youtube:
|
| 67 |
+
process_video(link_youtube, model, process_placeholder)
|
| 68 |
elif video == 'Webcam':
|
| 69 |
+
process_video('Webcam', model, process_placeholder)
|