import streamlit as st from google_storage import get_images_and_tables, bucket_name from vectorstore import query_chroma, client st.header("Rag Assistant") collections = [collection.name for collection in client.list_collections()] collection = st.selectbox(options=collections, label="Select a collection to query from") query = st.text_input(label="Ask the document") def display_images(images, tables, page_number): """Display the images in Streamlit""" if len(images) > 0: st.header(f"Image Gallery @ page {page_number}") cols = st.columns(len(images)) for i, (name, url) in enumerate(images): with cols[i]: st.image(url,caption=name) if len(tables) > 0: st.header(f"Table Gallery @ page {page_number}") cols = st.columns(len(tables)) for i, (name, url) in enumerate(tables): with cols[i]: st.image(url,caption=name) def search(query, collection): results = query_chroma(query, collection) st.write(results["answer"]) for page_number in results["sources"]: images, tables = get_images_and_tables(page_number, collection) display_images(images, tables, page_number) if __name__ == "__main__": if query != "": st.button(label="Ask", on_click=search(query, collection))