import streamlit as st
import tempfile

# Streamlit 網頁介面
st.title('上傳影片檔執行YOLO物體偵測')

# 上傳影片檔
source_video = st.file_uploader(label = '選擇上傳影片檔...')

if source_video:
    st.video(source_video)
    if st.button('執行'):
        with st.spinner('執行中...'):
            try:
                tfile = tempfile.NamedTemporaryFile()
                tfile.write(source_video.read())
                vid_cap = cv2.VideoCapture(tfile.name)
            except Exception as e:
                st.error(f'載入影片檔錯誤: {e}')        