Spaces:
Running
Running
import streamlit as st | |
import os | |
from dotenv import load_dotenv | |
from rag import Rag | |
from vectore_store.PineconeConnector import PineconeConnector | |
from vectore_store.VectoreStoreManager import VectoreStoreManager | |
from util import getYamlConfig | |
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["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']}"] = { | |
"num": chapter['num'], | |
"messages": [], | |
"prompt_system": chapter['prompt_system'], | |
"prompt": chapter['prompts'], | |
} | |
if 'parts' in config['variables']: | |
# Flatten structure by adding part name to each field | |
st.session_state["data_dict"] = [ | |
{**field, "part": part["name"]} | |
for part in config["variables"]["parts"] | |
for field in part["fields"] | |
] | |
else: | |
# Initialize session state with single list of variables | |
st.session_state["data_dict"] = [{**field} for field in config["variables"]] | |
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", title="Vos documents", icon="📂") | |
form = st.Page("pages/chapter_params.py", title="Paramètres", icon="📋") | |
chapters_pages = [ | |
st.Page(f"pages/chap_{chapter['num']}.py", title=chapter['name'], icon="📄") | |
for chapter in st.session_state["chapters"] | |
] | |
pg = st.navigation( | |
{ | |
"Documents": [ | |
documents, | |
], | |
"Configurations": [ | |
form, | |
], | |
"Dialogue": chapters_pages, | |
} | |
) | |
pg.run() | |
if __name__ == "__main__": | |
main() |