I am working on a streamlit app, and I want to display photos of some projects on the app. I have implemented a photo slide “photo_slider.html” with HTML and CSS, which works fine. I am now trying to incorporate it into the streamlit app but this is the result below
The images and the photo_slider.html file are saved in a folder called “projects”. the projects folder is saved in the same directory as the streamlit file app.py," yet the images dont display
Code:
import streamlit as st
from PIL import Image
import requests
from streamlit_lottie import st_lottie
import streamlit.components.v1 as com
import codecs
# ---- PROJECTS SLIDESHOW FUNCTION ----
def st_slideshow(photoslider_html, height=300):
slideshow_file = codecs.open(photoslider_html, 'r')
page = slideshow_file.read()
com.html(page, height=height)
# ---- MAIN FUNCTION ----
def main():
#---- ONGOING PROJECTS ----
st.markdown("**Ongoing Projects**")
st_slideshow("projects/photo_slider.html")
if __name__=='__main__':
main()
photo_slider.html code:
<!DOCTYPE html>
<html lang="en">
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container{
width: 100%;
height: 100vh;
background: wheat;
display: flex;
align-items: center;
justify-content: center;
}
.swiper{
width: 80%;
height: fit-content;
}
.swiper-slide img{
width: 100%;
}
.swiper .swiper-button-prev, .swiper .swiper-button-next{
color: orangered;
}
.swiper .swiper-pagination-bullet-active{
background: orangered;
}
</style>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Slider</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css"/>
</head>
<body>
<div class="container">
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide"><img src="img1.PNG"></div>
<div class="swiper-slide"><img src="img2.PNG"></div>
<div class="swiper-slide"><img src="img3.PNG"></div>
<div class="swiper-slide"><img src="img4.PNG"></div>
<div class="swiper-slide"><img src="img5.PNG"></div>
<div class="swiper-slide"><img src="img6.PNG"></div>
<div class="swiper-slide"><img src="img7.PNG"></div>
<div class="swiper-slide"><img src="img8.PNG"></div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.js"></script>
<script>
const swiper = new Swiper('.swiper', {
autoplay: {
delay: 3000,
disableOnInteraction: false,
},
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
clickable: true,
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
</script>
</body>
</html>