Rahulk2197 commited on
Commit
e02dd22
·
verified ·
1 Parent(s): bdd8282

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import zipfile
3
+ import os
4
+ import shutil
5
+ from moviepy.editor import VideoFileClip
6
+ from main import * # Ensure that `analyze_live_video` is properly imported
7
+ import random
8
+ import string
9
+
10
+ # Generate a random string of length 6
11
+
12
+ # Define paths
13
+ zip_file_path = 'output.zip'
14
+ output_folder = 'output'
15
+
16
+ # Function to process video and save output
17
+ def process_video(input_file_path, output_folder):
18
+ # Ensure the output folder exists
19
+ os.makedirs(output_folder, exist_ok=True)
20
+
21
+ # Load the video file
22
+ video = VideoFileClip(input_file_path)
23
+
24
+ # Example processing: Save each frame as an image (customize as needed)
25
+ for i, frame in enumerate(video.iter_frames()):
26
+ frame_path = os.path.join(output_folder, f'frame_{i:04d}.png')
27
+ # Save the frame as an image (you might need to use a library for this, e.g., PIL)
28
+ # Example: imageio.imwrite(frame_path, frame)
29
+
30
+ # You can add more processing steps here
31
+
32
+ # Streamlit app
33
+ st.title("Interview assistant")
34
+
35
+ # Upload video file
36
+ uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "avi", "mov"])
37
+
38
+ if uploaded_file is not None:
39
+ # Save the uploaded file to a temporary location
40
+ temp_file_path = 'temp_video_file.mp4'
41
+ with open(temp_file_path, 'wb') as f:
42
+ f.write(uploaded_file.read())
43
+
44
+ # Create a "Predict" button
45
+ if st.button("Predict"):
46
+ # Process the video and save output
47
+ uid = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
48
+ analyze_live_video(temp_file_path, uid, 1, 1, True, print)
49
+
50
+ # Compress the output folder into a ZIP file
51
+ def compress_folder(folder_path, zip_file_path):
52
+ with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
53
+ for root, dirs, files in os.walk(folder_path):
54
+ for file in files:
55
+ file_path = os.path.join(root, file)
56
+ zipf.write(file_path, os.path.relpath(file_path, folder_path))
57
+ compress_folder(output_folder, zip_file_path)
58
+
59
+ # Read the ZIP file to be downloaded
60
+ with open(zip_file_path, 'rb') as file:
61
+ zip_data = file.read()
62
+
63
+ # Create a download button for the ZIP file
64
+ st.download_button(
65
+ label="Download Processed output",
66
+ data=zip_data,
67
+ file_name="output.zip",
68
+ mime="application/zip"
69
+ )
70
+
71
+ # Clean up temporary files
72
+ os.remove(temp_file_path)
73
+ shutil.rmtree(output_folder)
74
+ os.remove(zip_file_path)