Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 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)
|