Spaces:
No application file
No application file
import streamlit as st | |
import os | |
from initiate import process_pdf # Assuming this function is implemented in the `initiate` module | |
# Streamlit Admin App | |
st.title("Admin: PDF and Video Processor") | |
# File Upload Section | |
st.header("Upload Files") | |
# PDF Upload | |
uploaded_pdf = st.file_uploader("Upload a PDF", type=["pdf"]) | |
# Video Upload | |
uploaded_videos = st.file_uploader( | |
"Upload Videos (multiple allowed)", type=["mp4"], accept_multiple_files=True | |
) | |
# Output Folder for Uploaded Files | |
upload_folder = "uploads" | |
os.makedirs(upload_folder, exist_ok=True) | |
# Save Uploaded Files | |
pdf_path = None | |
video_paths = [] | |
if uploaded_pdf: | |
pdf_path = os.path.join(upload_folder, uploaded_pdf.name) | |
with open(pdf_path, "wb") as f: | |
f.write(uploaded_pdf.read()) | |
st.success(f"Uploaded PDF: {uploaded_pdf.name}") | |
if uploaded_videos: | |
for video in uploaded_videos: | |
video_path = os.path.join(upload_folder, video.name) | |
with open(video_path, "wb") as f: | |
f.write(video.read()) | |
video_paths.append(video_path) | |
st.success(f"Uploaded {len(uploaded_videos)} videos") | |
# Process Button | |
if st.button("Start Processing"): | |
if not pdf_path: | |
st.error("Please upload a PDF before starting the process.") | |
elif not video_paths: | |
st.error("Please upload at least one video before starting the process.") | |
else: | |
try: | |
# Call the `process_pdf` function | |
process_pdf(pdf_path, video_paths) # video_paths is a list | |
st.success("Processing completed successfully!") | |
except Exception as e: | |
st.error(f"An error occurred during processing: {e}") | |