NEXAS commited on
Commit
84054cc
·
verified ·
1 Parent(s): e4bdc06

Update admin.py

Browse files
Files changed (1) hide show
  1. admin.py +53 -1
admin.py CHANGED
@@ -1 +1,53 @@
1
- from initiate import process_pdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from initiate import process_pdf # Assuming this function is implemented in the `initiate` module
4
+
5
+ # Streamlit Admin App
6
+ st.title("Admin: PDF and Video Processor")
7
+
8
+ # File Upload Section
9
+ st.header("Upload Files")
10
+
11
+ # PDF Upload
12
+ uploaded_pdf = st.file_uploader("Upload a PDF", type=["pdf"])
13
+
14
+ # Video Upload
15
+ uploaded_videos = st.file_uploader(
16
+ "Upload Videos (multiple allowed)", type=["mp4"], accept_multiple_files=True
17
+ )
18
+
19
+ # Output Folder for Uploaded Files
20
+ upload_folder = "uploads"
21
+ os.makedirs(upload_folder, exist_ok=True)
22
+
23
+ # Save Uploaded Files
24
+ pdf_path = None
25
+ video_paths = []
26
+
27
+ if uploaded_pdf:
28
+ pdf_path = os.path.join(upload_folder, uploaded_pdf.name)
29
+ with open(pdf_path, "wb") as f:
30
+ f.write(uploaded_pdf.read())
31
+ st.success(f"Uploaded PDF: {uploaded_pdf.name}")
32
+
33
+ if uploaded_videos:
34
+ for video in uploaded_videos:
35
+ video_path = os.path.join(upload_folder, video.name)
36
+ with open(video_path, "wb") as f:
37
+ f.write(video.read())
38
+ video_paths.append(video_path)
39
+ st.success(f"Uploaded {len(uploaded_videos)} videos")
40
+
41
+ # Process Button
42
+ if st.button("Start Processing"):
43
+ if not pdf_path:
44
+ st.error("Please upload a PDF before starting the process.")
45
+ elif not video_paths:
46
+ st.error("Please upload at least one video before starting the process.")
47
+ else:
48
+ try:
49
+ # Call the `process_pdf` function
50
+ process_pdf(pdf_path, video_paths) # video_paths is a list
51
+ st.success("Processing completed successfully!")
52
+ except Exception as e:
53
+ st.error(f"An error occurred during processing: {e}")