NeeravS commited on
Commit
926afdb
·
verified ·
1 Parent(s): 819dc49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -40
app.py CHANGED
@@ -20,50 +20,15 @@ if not os.path.exists(local_dir):
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
- # Streamlit interface setup
42
- st.title("Video Processing")
43
-
44
- # Step 1: File upload (Only define this once)
45
- uploaded_file = st.file_uploader(
46
- "Choose a video file...",
47
- type=["mp4", "avi", "mov", "mkv"],
48
- key="video_uploader"
49
- )
50
-
51
- # Ensure the upload logic only runs after a file is uploaded
52
- if uploaded_file is not None:
53
- saved_file_path = save_uploaded_file(uploaded_file)
54
- if saved_file_path:
55
- st.success("File uploaded and saved successfully!")
56
-
57
- if st.button("Process Video"):
58
- try:
59
- descriptions = extract_frames_and_describe(saved_file_path)
60
- video_summary = generate_summary(descriptions)
61
- st.success("Video processed successfully!")
62
- st.write(video_summary)
63
- except Exception as e:
64
- st.error(f"Failed to process video: {e}")
65
- finally:
66
- if os.path.exists(saved_file_path):
67
- os.remove(saved_file_path)
68
- else:
69
- st.error("Failed to save uploaded file.")
 
20
  sys.path.insert(0, local_dir)
21
  except Exception as e:
22
  st.error(f"Error cloning repository: {e}")
23
+ st.stop() # Stop the app if the repo can't be cloned
24
 
25
+ # Dynamically import and execute the app.py from the cloned repository
26
  try:
27
  import importlib.util
28
+ spec = importlib.util.spec_from_file_location("cloned_app", os.path.join(local_dir, "app.py"))
29
  module = importlib.util.module_from_spec(spec)
30
  spec.loader.exec_module(module)
31
 
 
 
 
 
 
 
32
  except Exception as e:
33
+ st.error(f"Error running the app from the cloned repo: {e}")
34
+ st.stop() # Stop the app if the cloned app can't be executed