Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
from git import Repo | |
import sys | |
# GitHub Repository and Directory Setup | |
repo_url = st.secrets["REPO_URL"] # The private repository URL | |
github_token = st.secrets["GITHUB_PAT"] # GitHub Personal Access Token | |
local_dir = "repo" | |
# Clone the private repository if it doesn't exist locally | |
if not os.path.exists(local_dir): | |
try: | |
repo_url = repo_url.replace("https://", f"https://{github_token}@") | |
st.write("Cloning the repository...") | |
Repo.clone_from(repo_url, local_dir) | |
st.success("Repository cloned successfully!") | |
# Add the repo directory to the system path | |
sys.path.insert(0, local_dir) | |
except Exception as e: | |
st.error(f"Error cloning repository: {e}") | |
# Dynamically import the functions after cloning | |
try: | |
import importlib.util | |
spec = importlib.util.spec_from_file_location("module.name", os.path.join(local_dir, "app.py")) | |
module = importlib.util.module_from_spec(spec) | |
spec.loader.exec_module(module) | |
# Now, functions from the cloned repo's app.py can be used | |
extract_frames_and_describe = module.extract_frames_and_describe | |
generate_summary = module.generate_summary | |
save_uploaded_file = module.save_uploaded_file | |
generate_captcha = module.generate_captcha | |
except Exception as e: | |
st.error(f"Error importing functions from cloned repo: {e}") | |
st.stop() # Stop the app if functions cannot be imported | |
# Video Summarization Interface | |
st.title("AI Based Video Summary Tool") | |
# Step 1: File upload | |
uploaded_file = st.file_uploader("Choose a video file...", type=["mp4", "avi", "mov", "mkv"]) | |
if uploaded_file is not None: | |
saved_file_path = save_uploaded_file(uploaded_file) | |
if saved_file_path: | |
st.success("File uploaded and saved successfully!") | |
if st.button("Process Video"): | |
try: | |
descriptions = extract_frames_and_describe(saved_file_path) | |
video_summary = generate_summary(descriptions) | |
st.success("Video processed successfully!") | |
st.write(video_summary) | |
except Exception as e: | |
st.error(f"Failed to process video: {e}") | |
finally: | |
if os.path.exists(saved_file_path): | |
os.remove(saved_file_path) | |
else: | |
st.error("Failed to save uploaded file.") | |
else: | |
st.error("Please upload a video file.") |