File size: 2,438 Bytes
c4e85f9
 
 
35eccef
c4e85f9
35eccef
 
 
 
c4e85f9
35eccef
c70aef4
35eccef
 
 
 
 
f4cafbc
 
 
35eccef
 
3c79350
f4cafbc
35eccef
f4cafbc
 
 
 
 
 
 
 
 
 
 
 
 
 
35eccef
 
3c79350
 
f4cafbc
 
35eccef
f4cafbc
 
 
 
35eccef
f4cafbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
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
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.")