Adi commited on
Commit
e147c15
1 Parent(s): 1618898

chore:updating autoplay

Browse files
Files changed (2) hide show
  1. app.py +9 -9
  2. render_final.py +4 -3
app.py CHANGED
@@ -36,8 +36,8 @@ def run_render_final(npy_file_path):
36
  command = ["python", "render_final.py", npy_file_path]
37
  try:
38
  gif_res = subprocess.run(command, check=True, text=True, capture_output=True)
39
- gif_file_path = find_latest_file('output', 'gif')
40
- return gif_file_path
41
  except subprocess.CalledProcessError as e:
42
  st.error(f"Error: {e.stderr}")
43
  return None
@@ -113,10 +113,10 @@ with button_col1:
113
  with button_col2:
114
  if st.button("Render Skeleton"):
115
  if 'npy_file_path' in st.session_state and st.session_state.npy_file_path:
116
- gif_file_path = run_render_final(st.session_state.npy_file_path)
117
- if gif_file_path:
118
- st.session_state.gif_file_path = gif_file_path
119
- st.session_state.gif_base64 = gif_to_base64(gif_file_path)
120
  else:
121
  st.error("No npy file found. Please generate HTML first.")
122
 
@@ -124,7 +124,7 @@ with button_col2:
124
  # Display the results side by side using HTML components
125
  if 'html_content' in st.session_state or 'gif_base64' in st.session_state:
126
  html_content = st.session_state.html_content if 'html_content' in st.session_state else ""
127
- gif_base64 = st.session_state.gif_base64 if 'gif_base64' in st.session_state else ""
128
 
129
  disp_col1, disp_col2 = st.columns([1, 1])
130
 
@@ -132,6 +132,6 @@ if 'html_content' in st.session_state or 'gif_base64' in st.session_state:
132
  components.html(html_content, height=800, scrolling=True)
133
 
134
  with disp_col2:
135
- if gif_base64:
136
- gif_html = f'<img src="data:image/gif;base64,{gif_base64}" style="width:100%;" loop="infinite">'
137
  components.html(gif_html, height=800, scrolling=True)
 
36
  command = ["python", "render_final.py", npy_file_path]
37
  try:
38
  gif_res = subprocess.run(command, check=True, text=True, capture_output=True)
39
+ vid_file_path = find_latest_file('output', 'mp4')
40
+ return vid_file_path
41
  except subprocess.CalledProcessError as e:
42
  st.error(f"Error: {e.stderr}")
43
  return None
 
113
  with button_col2:
114
  if st.button("Render Skeleton"):
115
  if 'npy_file_path' in st.session_state and st.session_state.npy_file_path:
116
+ vid_file_path = run_render_final(st.session_state.npy_file_path)
117
+ if vid_file_path:
118
+ st.session_state.vid_file_path = vid_file_path
119
+ # st.session_state.gif_base64 = gif_to_base64(gif_file_path)
120
  else:
121
  st.error("No npy file found. Please generate HTML first.")
122
 
 
124
  # Display the results side by side using HTML components
125
  if 'html_content' in st.session_state or 'gif_base64' in st.session_state:
126
  html_content = st.session_state.html_content if 'html_content' in st.session_state else ""
127
+ video_path = st.session_state.vid_file_path if 'vid_file_path' in st.session_state else ""
128
 
129
  disp_col1, disp_col2 = st.columns([1, 1])
130
 
 
132
  components.html(html_content, height=800, scrolling=True)
133
 
134
  with disp_col2:
135
+ if video_path:
136
+ gif_html = f'<video controls width="800" height="800"><source src="file:///{video_path}" type="video/mp4"></video autoplay>'
137
  components.html(gif_html, height=800, scrolling=True)
render_final.py CHANGED
@@ -18,7 +18,7 @@ import math
18
  # import ffmpeg
19
  from PIL import Image
20
  import argparse
21
-
22
  class WeakPerspectiveCamera(pyrender.Camera):
23
  def __init__(self,
24
  scale,
@@ -162,9 +162,10 @@ def render(motions, outdir='test_vis', device_id=0, name=None, pred=True):
162
 
163
  out = np.stack(vid, axis=0)
164
  gif_path = os.path.join(outdir, f'{name}.gif')
165
- imageio.mimsave(gif_path, out, fps=20)
166
-
167
 
 
 
168
 
169
 
170
  if __name__ == "__main__":
 
18
  # import ffmpeg
19
  from PIL import Image
20
  import argparse
21
+ import moviepy.editor as mp
22
  class WeakPerspectiveCamera(pyrender.Camera):
23
  def __init__(self,
24
  scale,
 
162
 
163
  out = np.stack(vid, axis=0)
164
  gif_path = os.path.join(outdir, f'{name}.gif')
165
+ imageio.mimwrite(gif_path, out, fps=20)
 
166
 
167
+ out_video = mp.VideoFileClip(gif_path)
168
+ out_video.write_videofile(gif_path.replace('.gif', '.mp4'), codec='libx264', fps=20)
169
 
170
 
171
  if __name__ == "__main__":