Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,29 +15,52 @@ if not os.path.exists(local_dir):
|
|
| 15 |
st.write("Cloning the repository...")
|
| 16 |
Repo.clone_from(repo_url, local_dir)
|
| 17 |
st.success("Repository cloned successfully!")
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
st.error(f"Error cloning repository: {e}")
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
sys.path.insert(0, local_dir)
|
| 23 |
-
|
| 24 |
-
# Import the necessary module from the cloned repository
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Video Summarization Interface
|
| 32 |
st.title("AI Based Video Summary Tool")
|
| 33 |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
if
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
st.write("Cloning the repository...")
|
| 16 |
Repo.clone_from(repo_url, local_dir)
|
| 17 |
st.success("Repository cloned successfully!")
|
| 18 |
+
|
| 19 |
+
# Add the repo directory to the system path
|
| 20 |
+
sys.path.insert(0, local_dir)
|
| 21 |
except Exception as e:
|
| 22 |
st.error(f"Error cloning repository: {e}")
|
| 23 |
|
| 24 |
+
# Dynamically import the functions after cloning
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
+
import importlib.util
|
| 27 |
+
spec = importlib.util.spec_from_file_location("module.name", os.path.join(local_dir, "app.py"))
|
| 28 |
+
module = importlib.util.module_from_spec(spec)
|
| 29 |
+
spec.loader.exec_module(module)
|
| 30 |
+
|
| 31 |
+
# Now, functions from the cloned repo's app.py can be used
|
| 32 |
+
extract_frames_and_describe = module.extract_frames_and_describe
|
| 33 |
+
generate_summary = module.generate_summary
|
| 34 |
+
save_uploaded_file = module.save_uploaded_file
|
| 35 |
+
generate_captcha = module.generate_captcha
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
st.error(f"Error importing functions from cloned repo: {e}")
|
| 39 |
+
st.stop() # Stop the app if functions cannot be imported
|
| 40 |
|
| 41 |
# Video Summarization Interface
|
| 42 |
st.title("AI Based Video Summary Tool")
|
| 43 |
|
| 44 |
+
# Step 1: File upload
|
| 45 |
+
uploaded_file = st.file_uploader("Choose a video file...", type=["mp4", "avi", "mov", "mkv"])
|
| 46 |
|
| 47 |
+
if uploaded_file is not None:
|
| 48 |
+
saved_file_path = save_uploaded_file(uploaded_file)
|
| 49 |
+
if saved_file_path:
|
| 50 |
+
st.success("File uploaded and saved successfully!")
|
| 51 |
|
| 52 |
+
if st.button("Process Video"):
|
| 53 |
+
try:
|
| 54 |
+
descriptions = extract_frames_and_describe(saved_file_path)
|
| 55 |
+
video_summary = generate_summary(descriptions)
|
| 56 |
+
st.success("Video processed successfully!")
|
| 57 |
+
st.write(video_summary)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
st.error(f"Failed to process video: {e}")
|
| 60 |
+
finally:
|
| 61 |
+
if os.path.exists(saved_file_path):
|
| 62 |
+
os.remove(saved_file_path)
|
| 63 |
+
else:
|
| 64 |
+
st.error("Failed to save uploaded file.")
|
| 65 |
+
else:
|
| 66 |
+
st.error("Please upload a video file.")
|