Help me optimize the logic of my app

Hello Everyone,

I’m looking to develop an interactive dashboard designed for TV display, which users can also access via their computers. I’d like to allow users to upload diverse file formats such as slideshows, PDFs, images, DOCX, etc. Once uploaded, the dashboard should automatically convert these files into images for display. Each image should be showcased in full-screen and should transition every 10 seconds, similar to a slideshow, given its primary display on a TV.

I have already implemented this functionality using Streamlit, but I’m seeking for a more efficient and enhanced solution. Here’s a brief overview of my implementation using Streamlit:

  1. A login page: Successful authentication grants the user access to a file uploader.
  2. Upon file upload, the document is converted first to PDF, and subsequently, each page is turned into a separate image.
  3. These images are then stored in a database.
  4. A script is deployed to create a unique page for each image, ensuring they remain in sequence.
  5. The generated pages are straightforward; they fetch the appropriate image from the database.
  6. The dashboard automatically transitions to the next page every 10 seconds.

Though this was my initial approach, I recognize it may not be the most efficient. I’m curious about how I can improve this functionality.
If you have insights on using a similar or a completely different logic, I’d appreciate the guidance.

Please feel free to ask if you need clarification on any aspect or require further details.

Thank you in advance!

So i tried implementing what you asked and yeah it went well but you need to make a good user database ,am using hardcoded creds now

import streamlit as st
from PIL import Image
import fitz  # PyMuPDF library for handling PDFs
import io
import time
def initialize_session_state():
    if not hasattr(st.session_state, "uploader"):
        st.session_state.uploader = []
        st.session_state.current_image_index = 0
def convert_pdf_to_images(file):
    pdf_data = io.BytesIO(
    pdf_document =, filetype="pdf")
    images = []
    for page_number in range(pdf_document.page_count):
        page = pdf_document.load_page(page_number)
        pix = page.get_pixmap()
        img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
    return images
def main():
    st.title("Interactive Dashboard")
    # Authentication (You can replace this with your authentication logic)
    username = st.text_input("Username")
    password = st.text_input("Password", type="password")
    if st.button("Login"):
        if username == "your_username" and password == "your_password":
            st.success("Logged in!")
            st.file_uploader("Upload Files", type=["pdf", "jpg", "png"], accept_multiple_files=True, key="uploader")
            st.error("Authentication failed. Please enter valid credentials.")
    global uploaded_files
    uploaded_files = st.session_state.uploader
    current_image_index = st.session_state.current_image_index
    if uploaded_files:
        st.write("Uploaded Files:")
        for file in uploaded_files:
        if current_image_index >= len(uploaded_files):
            current_image_index = 0
        if uploaded_files[current_image_index].type in ["image/jpeg", "image/png"]:
            img =[current_image_index])
            st.image(img, use_column_width=True)
        elif uploaded_files[current_image_index].type == "application/pdf":
            pdf_images = convert_pdf_to_images(uploaded_files[current_image_index])
            for img in pdf_images:
                img_placeholder = st.empty()
                img_placeholder.image(img, use_column_width=True)
                time.sleep(5)  # Sleep for 5 second between images
                img_placeholder.empty()  # Clear the image placeholder
        st.session_state.current_image_index += 1
        if current_image_index < len(uploaded_files):
            st.text("Next image will appear shortly...")
if __name__ == "__main__":

it accepts pdf and it changes page every 5 secs

Thank you, I like your idea with the empty placeholder. Did you think of any other way to do that ?

Nope not yet
I tried to implement but it gave one after other
so only this has helped something like slideshow