Rahulk2197 commited on
Commit
dd3c6f1
·
verified ·
1 Parent(s): d4ae07d

Update app.py

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