Spaces:
Runtime error
Runtime error
File size: 1,047 Bytes
ec44ead |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import os, sys
from os.path import dirname as up
sys.path.append(os.path.abspath(os.path.join(up(__file__), os.pardir)))
from utils import *
def handle_media_upload():
uploaded_file = st.file_uploader(
"**Drag and drop or upload an Image 🖼️ or a Video 📺**",
type=["jpg", "jpeg", "png", "mp4"],
)
media_content = ""
media_type = "image"
if uploaded_file is not None:
if uploaded_file.type.startswith("image/"):
media_content = Image.open(uploaded_file)
media_content = media_content.resize((500, 500))
st.image(media_content, caption="Uploaded Image.", use_column_width=True)
if uploaded_file.type.startswith("video/"):
file_bytes = uploaded_file.read()
data = base64.b64encode(file_bytes)
media_content = Part.from_data(
data=base64.b64decode(data), mime_type="video/mp4"
)
st.video(uploaded_file)
media_type = "video"
return media_content, media_type
|