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(file.read())
    pdf_document = fitz.open(stream=pdf_data, 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)
        images.append(img)
    pdf_document.close()
    return images
def main():
    initialize_session_state()
    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")
        else:
            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:
            st.write(file.name)
        if current_image_index >= len(uploaded_files):
            current_image_index = 0
        if uploaded_files[current_image_index].type in ["image/jpeg", "image/png"]:
            img = Image.open(uploaded_files[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...")
        time.sleep(5) 
if __name__ == "__main__":
    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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.