engrharis commited on
Commit
8d2aac4
·
verified ·
1 Parent(s): 37c899c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -1,22 +1,27 @@
1
  import streamlit as st
2
- from io import BytesIO
3
 
4
- # Display video as background
5
  def set_background_video():
6
- video_file = open("numbers moving background.mp4", "rb")
7
- video_bytes = video_file.read()
8
-
9
- video = BytesIO(video_bytes)
10
- st.markdown(
11
- f'<video autoplay loop muted style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;">'
12
- f'<source src="data:video/mp4;base64,{video_bytes.encode("base64")}" type="video/mp4">'
13
- f'</video>',
14
- unsafe_allow_html=True
15
- )
16
-
 
 
 
 
 
17
  set_background_video()
18
 
19
 
 
20
  import numpy as np
21
  import matplotlib.pyplot as plt
22
  from matplotlib.patches import Polygon, Circle
 
1
  import streamlit as st
2
+ import base64
3
 
 
4
  def set_background_video():
5
+ video_path = 'numbers moving background.mp4' # Path to your video file in Hugging Face Space
6
+ with open(video_path, 'rb') as video_file:
7
+ video_bytes = video_file.read()
8
+
9
+ # Encode the video to base64
10
+ video_base64 = base64.b64encode(video_bytes).decode('utf-8')
11
+
12
+ # HTML to embed the video as background
13
+ video_html = f"""
14
+ <video autoplay loop muted style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; z-index: -1;">
15
+ <source src="data:video/mp4;base64,{video_base64}" type="video/mp4">
16
+ </video>
17
+ """
18
+ st.markdown(video_html, unsafe_allow_html=True)
19
+
20
+ # Call the function to set the background video
21
  set_background_video()
22
 
23
 
24
+
25
  import numpy as np
26
  import matplotlib.pyplot as plt
27
  from matplotlib.patches import Polygon, Circle