import streamlit as st import os import base64 from dotenv import load_dotenv from rag import Rag from util import getYamlConfig from utils.document import generate_pdf load_dotenv() GROUP_NAME = os.environ.get("APP_NAME") LOGO = "assets/logo.png" userId = None def init_app(): config = getYamlConfig() query_params = st.query_params if "user" in query_params: global userId userId = query_params["user"] if len(st.session_state) == 0: st.session_state["messages"] = [] st.session_state["assistant"] = Rag() # st.session_state["data_dict"] = config['variables'] st.session_state["files"] = [] st.session_state["prompt_system"] = config['prompt_system'] st.session_state["chapters"] = config['chapters'] for chapter in st.session_state["chapters"]: st.session_state[f"chapter_{chapter['num']}"] = { "title": chapter['name'], "num": chapter['num'], "messages": [], "prompt_system": chapter['prompt_system'], "prompts": chapter['prompts'], } def main(): init_app() st.set_page_config(page_title=GROUP_NAME) st.logo(LOGO) st.title(GROUP_NAME) # st.write(f"**User ID:** {userId}") documents = st.Page("pages/documents.py", url_path="documents", title="Vos documents", icon="📂") form = st.Page("pages/chapter_params.py", url_path="configurations", title="Paramètres", icon="📋") chapters_pages = [ st.Page(f"pages/chap_{chapter['num']}.py", url_path=chapter['key'], title=chapter['name'], icon="📄") for chapter in st.session_state["chapters"] ] pg = st.navigation( { "Documents": [ documents, ], "Configurations": [ form, ], "Dialogue": chapters_pages, } ) st.session_state["displaySystemOnPDF"] = st.sidebar.checkbox("Afficher le prompt système", value=True) if st.sidebar.button("Générer le PDF"): chapters = [] for chapter in st.session_state["chapters"]: chapters.append(st.session_state[f"chapter_{chapter['num']}"]) pdf_buffer = generate_pdf(chapters, displayPromptSystem=st.session_state["displaySystemOnPDF"]) st.sidebar.download_button( label="📥 Télécharger le PDF", data=pdf_buffer, file_name="diagnostique_CEGARA.pdf", mime="application/pdf" ) st.sidebar.markdown("### Documentation") st.sidebar.markdown("*Documentation :* [*Lien*]({})".format("https://docs.google.com/presentation/d/1b-cnCKge1qRBS26U5FfMScQPco4gZTn7tN1idhccsso/edit?usp=sharing")) st.sidebar.markdown("*Evaluation App. IA :*") st.sidebar.markdown("---") st.sidebar.image("./assets/bziiit.png", width=100) st.sidebar.markdown(""" """, unsafe_allow_html=True) st.sidebar.markdown("") st.sidebar.markdown("",unsafe_allow_html=True) st.sidebar.markdown("2025 : Open source en Licence MIT") st.sidebar.markdown("info@bziiit.com") pg.run() if __name__ == "__main__": main()