David Chuan-En Lin commited on
Commit
d2e201b
·
1 Parent(s): db499bc
Files changed (2) hide show
  1. README.md +2 -2
  2. videogenic.py +15 -10
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Videogenic
3
  emoji: ✨
4
- colorFrom: purple
5
- colorTo: pink
6
  sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: videogenic.py
 
1
  ---
2
  title: Videogenic
3
  emoji: ✨
4
+ colorFrom: pink
5
+ colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: videogenic.py
videogenic.py CHANGED
@@ -30,6 +30,18 @@ from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
30
  from moviepy.editor import *
31
  import glob
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  def fetch_video(url):
34
  yt = YouTube(url)
35
  streams = yt.streams.filter(adaptive=True, subtype='mp4', resolution='360p', only_video=True)
@@ -490,15 +502,7 @@ if 'progress' not in st.session_state:
490
 
491
  if st.session_state.progress == 1:
492
  with st.spinner('Loading model...'):
493
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
494
- model, preprocess = openai_clip.load('ViT-B/32', device=device)
495
- if 'model' not in st.session_state:
496
- st.session_state.model = model
497
- st.session_state.preprocess = preprocess
498
- st.session_state.device = device
499
- st.session_state.model = model
500
- st.session_state.preprocess = preprocess
501
- st.session_state.device = device
502
  domain = st.selectbox('Select video',('Skydiving', 'Surfing')) # Entire journey, montage, vlog
503
  if 'domain' not in st.session_state:
504
  st.session_state.domain = domain
@@ -591,10 +595,11 @@ if st.session_state.progress == 2:
591
  if st.button('Generate video'):
592
  with st.spinner('Generating highlight video...'):
593
  edit_video(template, st.session_state.df_all)
 
594
  elif st.session_state.mode == 'User selection':
595
  if st.button('Generate video'):
596
  left = st.session_state.selection['x'][0]
597
  right = st.session_state.selection['x'][1]
598
  with st.spinner('Generating highlight video...'):
599
  crop_video(st.session_state.df_all, left, right)
600
- st.balloons()
 
30
  from moviepy.editor import *
31
  import glob
32
 
33
+ @st.cache(show_spinner=False)
34
+ def load_mode():
35
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
36
+ model, preprocess = openai_clip.load('ViT-B/32', device=device)
37
+ if 'model' not in st.session_state:
38
+ st.session_state.model = model
39
+ st.session_state.preprocess = preprocess
40
+ st.session_state.device = device
41
+ st.session_state.model = model
42
+ st.session_state.preprocess = preprocess
43
+ st.session_state.device = device
44
+
45
  def fetch_video(url):
46
  yt = YouTube(url)
47
  streams = yt.streams.filter(adaptive=True, subtype='mp4', resolution='360p', only_video=True)
 
502
 
503
  if st.session_state.progress == 1:
504
  with st.spinner('Loading model...'):
505
+ load_model()
 
 
 
 
 
 
 
 
506
  domain = st.selectbox('Select video',('Skydiving', 'Surfing')) # Entire journey, montage, vlog
507
  if 'domain' not in st.session_state:
508
  st.session_state.domain = domain
 
595
  if st.button('Generate video'):
596
  with st.spinner('Generating highlight video...'):
597
  edit_video(template, st.session_state.df_all)
598
+ st.balloons()
599
  elif st.session_state.mode == 'User selection':
600
  if st.button('Generate video'):
601
  left = st.session_state.selection['x'][0]
602
  right = st.session_state.selection['x'][1]
603
  with st.spinner('Generating highlight video...'):
604
  crop_video(st.session_state.df_all, left, right)
605
+ st.balloons()