Spaces:
Sleeping
Sleeping
cd@bziiit.com commited on
Commit ·
c3b4e7b
1
Parent(s): 4e9fde0
Include multiple companies forms
Browse files- app.py +38 -16
- config.yaml +262 -106
- pages/__init__.py +1 -0
- pages/afp.py +131 -0
- pages/cettons.py +131 -0
- pages/chatbot_afp.py +147 -0
- pages/chatbot_cettons.py +147 -0
- pages/{chatbot.py → chatbot_steel.py} +10 -8
- pages/form.py +16 -6
- pages/steel.py +131 -0
app.py
CHANGED
|
@@ -14,6 +14,8 @@ load_dotenv()
|
|
| 14 |
GROUP_NAME = os.environ.get("APP_NAME")
|
| 15 |
LOGO = "assets/logo.png"
|
| 16 |
|
|
|
|
|
|
|
| 17 |
def init_app():
|
| 18 |
|
| 19 |
config = getYamlConfig()
|
|
@@ -27,19 +29,30 @@ def init_app():
|
|
| 27 |
st.session_state["messages"] = []
|
| 28 |
st.session_state["remove_undefined_value"] = True
|
| 29 |
st.session_state["assistant"] = Rag(vectore_store=vs_manager)
|
| 30 |
-
st.session_state["data_dict"] =
|
|
|
|
| 31 |
st.session_state["prompt_system"] = config['prompt_system']
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
def main():
|
|
@@ -66,8 +79,7 @@ def main():
|
|
| 66 |
saved_documents = st.Page("pages/persistent_documents.py", title="Communs", icon="🗃️")
|
| 67 |
documents = st.Page("pages/documents.py", title="Vos documents", icon="📂")
|
| 68 |
prompt_system = st.Page("pages/prompt_system.py", title="Prompt système", icon="🖊️")
|
| 69 |
-
|
| 70 |
-
chatbot = st.Page("pages/chatbot.py", title="Chatbot", icon="🤖", default=True)
|
| 71 |
|
| 72 |
pg = st.navigation(
|
| 73 |
{
|
|
@@ -77,11 +89,21 @@ def main():
|
|
| 77 |
],
|
| 78 |
"Configurations": [
|
| 79 |
prompt_system,
|
| 80 |
-
form,
|
| 81 |
],
|
| 82 |
-
"
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
)
|
| 87 |
|
|
|
|
| 14 |
GROUP_NAME = os.environ.get("APP_NAME")
|
| 15 |
LOGO = "assets/logo.png"
|
| 16 |
|
| 17 |
+
COMPANIES = []
|
| 18 |
+
|
| 19 |
def init_app():
|
| 20 |
|
| 21 |
config = getYamlConfig()
|
|
|
|
| 29 |
st.session_state["messages"] = []
|
| 30 |
st.session_state["remove_undefined_value"] = True
|
| 31 |
st.session_state["assistant"] = Rag(vectore_store=vs_manager)
|
| 32 |
+
st.session_state["data_dict"] = {}
|
| 33 |
+
st.session_state["company_code"] = None
|
| 34 |
st.session_state["prompt_system"] = config['prompt_system']
|
| 35 |
|
| 36 |
+
# Initialize data_dict for each company
|
| 37 |
+
for company in config['companies']:
|
| 38 |
+
COMPANIES.append(company)
|
| 39 |
+
company_code = company['code']
|
| 40 |
+
|
| 41 |
+
st.session_state["data_dict"][company_code] = []
|
| 42 |
+
|
| 43 |
+
if 'parts' in company['variables']:
|
| 44 |
+
# Flatten structure by adding part name to each field
|
| 45 |
+
st.session_state["data_dict"][company_code] = [
|
| 46 |
+
{**field, "part": part["name"]}
|
| 47 |
+
for part in company["variables"]["parts"]
|
| 48 |
+
for field in part["fields"]
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
else:
|
| 52 |
+
# Initialize session state with single list of variables
|
| 53 |
+
st.session_state["data_dict"][company_code] = [
|
| 54 |
+
{**field} for field in company["variables"]
|
| 55 |
+
]
|
| 56 |
|
| 57 |
|
| 58 |
def main():
|
|
|
|
| 79 |
saved_documents = st.Page("pages/persistent_documents.py", title="Communs", icon="🗃️")
|
| 80 |
documents = st.Page("pages/documents.py", title="Vos documents", icon="📂")
|
| 81 |
prompt_system = st.Page("pages/prompt_system.py", title="Prompt système", icon="🖊️")
|
| 82 |
+
# chatbot = st.Page("pages/chatbot.py", title="Chatbot", icon="🤖", default=True)
|
|
|
|
| 83 |
|
| 84 |
pg = st.navigation(
|
| 85 |
{
|
|
|
|
| 89 |
],
|
| 90 |
"Configurations": [
|
| 91 |
prompt_system,
|
|
|
|
| 92 |
],
|
| 93 |
+
"Auto France Parts": [
|
| 94 |
+
st.Page("pages/afp.py", title="Paramètres", icon="📋"),
|
| 95 |
+
st.Page("pages/chatbot_afp.py", title="Dialogue", icon="🤖", default=True),
|
| 96 |
+
],
|
| 97 |
+
"La Pyramide des Cettons": [
|
| 98 |
+
st.Page("pages/cettons.py", title="Paramètres", icon="📋"),
|
| 99 |
+
st.Page("pages/chatbot_cettons.py", title="Dialogue", icon="🤖"),
|
| 100 |
+
|
| 101 |
],
|
| 102 |
+
"Steel France": [
|
| 103 |
+
st.Page("pages/steel.py", title="Paramètres", icon="📋"),
|
| 104 |
+
st.Page("pages/chatbot_steel.py", title="Dialogue", icon="🤖"),
|
| 105 |
+
|
| 106 |
+
]
|
| 107 |
}
|
| 108 |
)
|
| 109 |
|
config.yaml
CHANGED
|
@@ -48,113 +48,269 @@ prompts:
|
|
| 48 |
# Chaque 'part' représente une section contenant un groupe de champs (par exemple : Panier, Livraison).
|
| 49 |
# La clé 'number' permet d’ordonner les sections.
|
| 50 |
# Pour activer cette version, commentez la Version 1 ci-dessus et décommentez cette section.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
variables:
|
| 53 |
-
parts:
|
| 54 |
-
- name: "Exploitant"
|
| 55 |
-
number: 1
|
| 56 |
-
fields:
|
| 57 |
-
- label: "Nom de l'exploitation"
|
| 58 |
-
nature: ''
|
| 59 |
-
key: exploitation_name
|
| 60 |
-
value: "Auto France Parts"
|
| 61 |
-
|
| 62 |
-
# - label: "Localisation"
|
| 63 |
-
# nature: 'selectbox'
|
| 64 |
-
# key: localisation
|
| 65 |
-
# options: ["Nouvelle-Aquitaine"]
|
| 66 |
-
# value: "Nouvelle-Aquitaine"
|
| 67 |
-
|
| 68 |
-
- label: "Type d'activité"
|
| 69 |
-
nature: ''
|
| 70 |
-
key: type_activite
|
| 71 |
-
value: "Commerce de gros d'équipements automobiles"
|
| 72 |
-
|
| 73 |
-
# - label: "Spécificités et/ou Certifications"
|
| 74 |
-
# nature: 'multiselect'
|
| 75 |
-
# key: specificite_certifications
|
| 76 |
-
# options: ["Bio Oui Partielle", "Bio Oui Totale", "HVE (Haute Valeur Environnementale)", "TCS (Techniques Culturales Simplifiées)"]
|
| 77 |
-
# value:
|
| 78 |
-
|
| 79 |
-
- label: "Date de création de l'entreprise"
|
| 80 |
-
nature: 'date'
|
| 81 |
-
key: date_creation
|
| 82 |
-
value:
|
| 83 |
-
|
| 84 |
-
- label: "Chiffre d'affaires annuel (en €)"
|
| 85 |
-
nature: 'numeric'
|
| 86 |
-
key: ca_annuel
|
| 87 |
-
value: 72000000
|
| 88 |
-
|
| 89 |
-
- label: "EBE (Excédent Brut d'Exploitation, en €)"
|
| 90 |
-
nature: 'numeric'
|
| 91 |
-
key: ebe
|
| 92 |
-
value: 0
|
| 93 |
-
|
| 94 |
-
- label: "Total Bilan"
|
| 95 |
-
nature: 'numeric'
|
| 96 |
-
key: total_bilan
|
| 97 |
-
value: 0
|
| 98 |
-
|
| 99 |
-
- label: "Nombre de salarié"
|
| 100 |
-
nature: 'numeric'
|
| 101 |
-
key: nb_salaries
|
| 102 |
-
value: 20
|
| 103 |
-
|
| 104 |
-
- name: "Type de projet"
|
| 105 |
-
number: 2
|
| 106 |
-
fields:
|
| 107 |
-
- label: "Description du projet ou événement important pour l’entreprise"
|
| 108 |
-
nature: 'text_area'
|
| 109 |
-
key: projet_description
|
| 110 |
-
value: ""
|
| 111 |
-
|
| 112 |
-
- label: "Catégorie du projet"
|
| 113 |
-
nature: 'selectbox'
|
| 114 |
-
key: projet_categorie
|
| 115 |
-
options: ["Toutes", "Innovation", "Durabilité", "Développement", "Formation"]
|
| 116 |
-
value: "Toutes"
|
| 117 |
-
|
| 118 |
-
- label: "Budget Minimum"
|
| 119 |
-
nature: 'numeric'
|
| 120 |
-
key: budget_minimum
|
| 121 |
-
value: 1000
|
| 122 |
-
|
| 123 |
-
- label: "Budget Maximum"
|
| 124 |
-
nature: 'numeric'
|
| 125 |
-
key: budget_maximum
|
| 126 |
-
value: 6000000
|
| 127 |
-
|
| 128 |
-
# - label: "Budget total estimé"
|
| 129 |
-
# nature: 'slider'
|
| 130 |
-
# key: projet_budget
|
| 131 |
-
# value: [] # Valeur par défaut
|
| 132 |
-
# min: 0
|
| 133 |
-
# max: 50000
|
| 134 |
-
# step: 500
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
- name: "Critères de Subvention"
|
| 138 |
-
number: 3
|
| 139 |
-
fields:
|
| 140 |
-
- label: "Périmètre géographique de recherche"
|
| 141 |
-
nature: 'multiselect'
|
| 142 |
-
key: recherche_geo
|
| 143 |
-
options: [ "Tous", "Départemental", "Régional", "National", "Européen" ]
|
| 144 |
-
value: "Tous"
|
| 145 |
-
|
| 146 |
-
- label: "Type de subvention souhaitée"
|
| 147 |
-
nature: 'multiselect'
|
| 148 |
-
key: subvention_type
|
| 149 |
-
options: [ "Tous", "Avance − Prêts − Garanties", "Subvention", "Prise en charge des coûts et allègement des charges", "Autres" ]
|
| 150 |
-
value: "Tous"
|
| 151 |
-
|
| 152 |
-
- label: "Thématique de l'aide"
|
| 153 |
-
nature: 'multiselect'
|
| 154 |
-
key: subvention_thematic
|
| 155 |
-
options: [ "Tous", "Crise énergétique", "France 2030", "Plan résilience" ]
|
| 156 |
-
value: "Tous"
|
| 157 |
-
|
| 158 |
|
| 159 |
prompt_system: "
|
| 160 |
Informations générales de l'exploitation agricole :
|
|
|
|
| 48 |
# Chaque 'part' représente une section contenant un groupe de champs (par exemple : Panier, Livraison).
|
| 49 |
# La clé 'number' permet d’ordonner les sections.
|
| 50 |
# Pour activer cette version, commentez la Version 1 ci-dessus et décommentez cette section.
|
| 51 |
+
companies:
|
| 52 |
+
- name: "Auto France Parts"
|
| 53 |
+
code: "afp_"
|
| 54 |
+
variables:
|
| 55 |
+
parts:
|
| 56 |
+
- name: "Exploitant"
|
| 57 |
+
number: 1
|
| 58 |
+
fields:
|
| 59 |
+
- label: "Nom de l'exploitation"
|
| 60 |
+
nature: ''
|
| 61 |
+
key: exploitation_name
|
| 62 |
+
value: "Auto France Parts"
|
| 63 |
+
|
| 64 |
+
- label: "Type d'activité"
|
| 65 |
+
nature: ''
|
| 66 |
+
key: type_activite
|
| 67 |
+
value: "Commerce de gros d'équipements automobiles"
|
| 68 |
+
|
| 69 |
+
- label: "Date de création de l'entreprise"
|
| 70 |
+
nature: 'date'
|
| 71 |
+
key: date_creation
|
| 72 |
+
value:
|
| 73 |
+
|
| 74 |
+
- label: "Chiffre d'affaires annuel (en €)"
|
| 75 |
+
nature: 'numeric'
|
| 76 |
+
key: ca_annuel
|
| 77 |
+
value: 72000000
|
| 78 |
+
|
| 79 |
+
- label: "EBE (Excédent Brut d'Exploitation, en €)"
|
| 80 |
+
nature: 'numeric'
|
| 81 |
+
key: ebe
|
| 82 |
+
value: 0
|
| 83 |
+
|
| 84 |
+
- label: "Total Bilan"
|
| 85 |
+
nature: 'numeric'
|
| 86 |
+
key: total_bilan
|
| 87 |
+
value: 0
|
| 88 |
+
|
| 89 |
+
- label: "Nombre de salarié"
|
| 90 |
+
nature: 'numeric'
|
| 91 |
+
key: nb_salaries
|
| 92 |
+
value: 20
|
| 93 |
+
|
| 94 |
+
- name: "Type de projet"
|
| 95 |
+
number: 2
|
| 96 |
+
fields:
|
| 97 |
+
- label: "Description du projet ou événement important pour l’entreprise"
|
| 98 |
+
nature: 'text_area'
|
| 99 |
+
key: projet_description
|
| 100 |
+
value: ""
|
| 101 |
+
|
| 102 |
+
- label: "Catégorie du projet"
|
| 103 |
+
nature: 'selectbox'
|
| 104 |
+
key: projet_categorie
|
| 105 |
+
options: ["Toutes", "Innovation", "Durabilité", "Développement", "Formation"]
|
| 106 |
+
value: "Toutes"
|
| 107 |
+
|
| 108 |
+
- label: "Budget Minimum"
|
| 109 |
+
nature: 'numeric'
|
| 110 |
+
key: budget_minimum
|
| 111 |
+
value: 1000
|
| 112 |
+
|
| 113 |
+
- label: "Budget Maximum"
|
| 114 |
+
nature: 'numeric'
|
| 115 |
+
key: budget_maximum
|
| 116 |
+
value: 6000000
|
| 117 |
+
|
| 118 |
+
- name: "Critères de Subvention"
|
| 119 |
+
number: 3
|
| 120 |
+
fields:
|
| 121 |
+
- label: "Périmètre géographique de recherche"
|
| 122 |
+
nature: 'multiselect'
|
| 123 |
+
key: recherche_geo
|
| 124 |
+
options: [ "Tous", "Départemental", "Régional", "National", "Européen" ]
|
| 125 |
+
value: "Tous"
|
| 126 |
+
|
| 127 |
+
- label: "Type de subvention souhaitée"
|
| 128 |
+
nature: 'multiselect'
|
| 129 |
+
key: subvention_type
|
| 130 |
+
options: [ "Tous", "Avance − Prêts − Garanties", "Subvention", "Prise en charge des coûts et allègement des charges", "Autres" ]
|
| 131 |
+
value: "Tous"
|
| 132 |
+
|
| 133 |
+
- label: "Thématique de l'aide"
|
| 134 |
+
nature: 'multiselect'
|
| 135 |
+
key: subvention_thematic
|
| 136 |
+
options: [ "Tous", "Crise énergétique", "France 2030", "Plan résilience" ]
|
| 137 |
+
value: "Tous"
|
| 138 |
+
|
| 139 |
+
- name: "Steel France"
|
| 140 |
+
code: "steel_"
|
| 141 |
+
variables:
|
| 142 |
+
parts:
|
| 143 |
+
- name: "Exploitant"
|
| 144 |
+
number: 1
|
| 145 |
+
fields:
|
| 146 |
+
- label: "Nom de l'exploitation"
|
| 147 |
+
nature: ''
|
| 148 |
+
key: exploitation_name
|
| 149 |
+
value: "Steel France"
|
| 150 |
+
|
| 151 |
+
- label: "Type d'activité"
|
| 152 |
+
nature: ''
|
| 153 |
+
key: type_activite
|
| 154 |
+
value: "Commerce de gros d'équipements automobiles"
|
| 155 |
+
|
| 156 |
+
- label: "Date de création de l'entreprise"
|
| 157 |
+
nature: 'date'
|
| 158 |
+
key: date_creation
|
| 159 |
+
value:
|
| 160 |
+
|
| 161 |
+
- label: "Chiffre d'affaires annuel (en €)"
|
| 162 |
+
nature: 'numeric'
|
| 163 |
+
key: ca_annuel
|
| 164 |
+
value:
|
| 165 |
+
|
| 166 |
+
- label: "EBE (Excédent Brut d'Exploitation, en €)"
|
| 167 |
+
nature: 'numeric'
|
| 168 |
+
key: ebe
|
| 169 |
+
value: 0
|
| 170 |
+
|
| 171 |
+
- label: "Total Bilan"
|
| 172 |
+
nature: 'numeric'
|
| 173 |
+
key: total_bilan
|
| 174 |
+
value: 0
|
| 175 |
+
|
| 176 |
+
- label: "Nombre de salarié"
|
| 177 |
+
nature: 'numeric'
|
| 178 |
+
key: nb_salaries
|
| 179 |
+
value: 0
|
| 180 |
+
|
| 181 |
+
- name: "Type de projet"
|
| 182 |
+
number: 2
|
| 183 |
+
fields:
|
| 184 |
+
- label: "Description du projet ou événement important pour l’entreprise"
|
| 185 |
+
nature: 'text_area'
|
| 186 |
+
key: projet_description
|
| 187 |
+
value: ""
|
| 188 |
+
|
| 189 |
+
- label: "Catégorie du projet"
|
| 190 |
+
nature: 'selectbox'
|
| 191 |
+
key: projet_categorie
|
| 192 |
+
options: ["Toutes", "Innovation", "Durabilité", "Développement", "Formation"]
|
| 193 |
+
value: "Toutes"
|
| 194 |
+
|
| 195 |
+
- label: "Budget Minimum"
|
| 196 |
+
nature: 'numeric'
|
| 197 |
+
key: budget_minimum
|
| 198 |
+
value: 1000
|
| 199 |
+
|
| 200 |
+
- label: "Budget Maximum"
|
| 201 |
+
nature: 'numeric'
|
| 202 |
+
key: budget_maximum
|
| 203 |
+
value: 6000000
|
| 204 |
+
|
| 205 |
+
- name: "Critères de Subvention"
|
| 206 |
+
number: 3
|
| 207 |
+
fields:
|
| 208 |
+
- label: "Périmètre géographique de recherche"
|
| 209 |
+
nature: 'multiselect'
|
| 210 |
+
key: recherche_geo
|
| 211 |
+
options: [ "Tous", "Départemental", "Régional", "National", "Européen" ]
|
| 212 |
+
value: "Tous"
|
| 213 |
+
|
| 214 |
+
- label: "Type de subvention souhaitée"
|
| 215 |
+
nature: 'multiselect'
|
| 216 |
+
key: subvention_type
|
| 217 |
+
options: [ "Tous", "Avance − Prêts − Garanties", "Subvention", "Prise en charge des coûts et allègement des charges", "Autres" ]
|
| 218 |
+
value: "Tous"
|
| 219 |
+
|
| 220 |
+
- label: "Thématique de l'aide"
|
| 221 |
+
nature: 'multiselect'
|
| 222 |
+
key: subvention_thematic
|
| 223 |
+
options: [ "Tous", "Crise énergétique", "France 2030", "Plan résilience" ]
|
| 224 |
+
value: "Tous"
|
| 225 |
+
|
| 226 |
+
- name: "La pyramide des Cettons"
|
| 227 |
+
code: "cettons_"
|
| 228 |
+
variables:
|
| 229 |
+
parts:
|
| 230 |
+
- name: "Exploitant"
|
| 231 |
+
number: 1
|
| 232 |
+
fields:
|
| 233 |
+
- label: "Nom de l'exploitation"
|
| 234 |
+
nature: ''
|
| 235 |
+
key: exploitation_name
|
| 236 |
+
value: "La pyramide des Cettons"
|
| 237 |
+
|
| 238 |
+
- label: "Type d'activité"
|
| 239 |
+
nature: ''
|
| 240 |
+
key: type_activite
|
| 241 |
+
value: "Location de terrains et d'autres biens immobiliers"
|
| 242 |
+
|
| 243 |
+
- label: "Date de création de l'entreprise"
|
| 244 |
+
nature: 'date'
|
| 245 |
+
key: date_creation
|
| 246 |
+
value:
|
| 247 |
+
|
| 248 |
+
- label: "Chiffre d'affaires annuel (en €)"
|
| 249 |
+
nature: 'numeric'
|
| 250 |
+
key: ca_annuel
|
| 251 |
+
value: 0
|
| 252 |
+
|
| 253 |
+
- label: "EBE (Excédent Brut d'Exploitation, en €)"
|
| 254 |
+
nature: 'numeric'
|
| 255 |
+
key: ebe
|
| 256 |
+
value: 0
|
| 257 |
+
|
| 258 |
+
- label: "Total Bilan"
|
| 259 |
+
nature: 'numeric'
|
| 260 |
+
key: total_bilan
|
| 261 |
+
value: 0
|
| 262 |
+
|
| 263 |
+
- label: "Nombre de salarié"
|
| 264 |
+
nature: 'numeric'
|
| 265 |
+
key: nb_salaries
|
| 266 |
+
value: 0
|
| 267 |
+
|
| 268 |
+
- name: "Type de projet"
|
| 269 |
+
number: 2
|
| 270 |
+
fields:
|
| 271 |
+
- label: "Description du projet ou événement important pour l’entreprise"
|
| 272 |
+
nature: 'text_area'
|
| 273 |
+
key: projet_description
|
| 274 |
+
value: ""
|
| 275 |
+
|
| 276 |
+
- label: "Catégorie du projet"
|
| 277 |
+
nature: 'selectbox'
|
| 278 |
+
key: projet_categorie
|
| 279 |
+
options: ["Toutes", "Innovation", "Durabilité", "Développement", "Formation"]
|
| 280 |
+
value: "Toutes"
|
| 281 |
+
|
| 282 |
+
- label: "Budget Minimum"
|
| 283 |
+
nature: 'numeric'
|
| 284 |
+
key: budget_minimum
|
| 285 |
+
value: 1000
|
| 286 |
+
|
| 287 |
+
- label: "Budget Maximum"
|
| 288 |
+
nature: 'numeric'
|
| 289 |
+
key: budget_maximum
|
| 290 |
+
value: 6000000
|
| 291 |
+
|
| 292 |
+
- name: "Critères de Subvention"
|
| 293 |
+
number: 3
|
| 294 |
+
fields:
|
| 295 |
+
- label: "Périmètre géographique de recherche"
|
| 296 |
+
nature: 'multiselect'
|
| 297 |
+
key: recherche_geo
|
| 298 |
+
options: [ "Tous", "Départemental", "Régional", "National", "Européen" ]
|
| 299 |
+
value: "Tous"
|
| 300 |
+
|
| 301 |
+
- label: "Type de subvention souhaitée"
|
| 302 |
+
nature: 'multiselect'
|
| 303 |
+
key: subvention_type
|
| 304 |
+
options: [ "Tous", "Avance − Prêts − Garanties", "Subvention", "Prise en charge des coûts et allègement des charges", "Autres" ]
|
| 305 |
+
value: "Tous"
|
| 306 |
+
|
| 307 |
+
- label: "Thématique de l'aide"
|
| 308 |
+
nature: 'multiselect'
|
| 309 |
+
key: subvention_thematic
|
| 310 |
+
options: [ "Tous", "Crise énergétique", "France 2030", "Plan résilience" ]
|
| 311 |
+
value: "Tous"
|
| 312 |
+
|
| 313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
prompt_system: "
|
| 316 |
Informations générales de l'exploitation agricole :
|
pages/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# ...no code needed...
|
pages/afp.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from util import getYamlConfig
|
| 4 |
+
|
| 5 |
+
company_code = "afp_"
|
| 6 |
+
|
| 7 |
+
def update_session_state(key,):
|
| 8 |
+
# Get new value from session state and change key for save it in params
|
| 9 |
+
new_value = st.session_state[key]
|
| 10 |
+
key = key[5:]
|
| 11 |
+
|
| 12 |
+
for item in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 13 |
+
if item['key'] == key:
|
| 14 |
+
item['value'] = new_value
|
| 15 |
+
break
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def page():
|
| 19 |
+
st.subheader("Définissez vos paramètres")
|
| 20 |
+
st.text("L'ensemble des critères sont facultatifs.")
|
| 21 |
+
|
| 22 |
+
st.session_state["company_code"] = company_code
|
| 23 |
+
company_config = None
|
| 24 |
+
|
| 25 |
+
# Charge la configuration YAML
|
| 26 |
+
config = getYamlConfig()
|
| 27 |
+
|
| 28 |
+
for company in config['companies']:
|
| 29 |
+
if company['code'] == st.session_state["company_code"]:
|
| 30 |
+
company_config = company
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Vérifie si la structure inclut des 'parts' ou une liste de variables
|
| 34 |
+
if 'parts' in company_config['variables']:
|
| 35 |
+
# Cas avec 'parts' : Trie les parts et affiche les champs par onglet
|
| 36 |
+
parts = company_config["variables"]["parts"]
|
| 37 |
+
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf')))
|
| 38 |
+
|
| 39 |
+
# Création de tabs pour chaque 'part' trié
|
| 40 |
+
tabs = st.tabs([part['name'] for part in parts_sorted])
|
| 41 |
+
for part, tab in zip(parts_sorted, tabs):
|
| 42 |
+
with tab:
|
| 43 |
+
for field in part['fields']:
|
| 44 |
+
for field_session in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 45 |
+
if field['key'] == field_session['key']:
|
| 46 |
+
display_field(field_session)
|
| 47 |
+
else:
|
| 48 |
+
# Display fields directly if no parts are defined
|
| 49 |
+
for field in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 50 |
+
display_field(field)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def display_field(field):
|
| 54 |
+
"""Helper function to create the correct input based on field 'nature'."""
|
| 55 |
+
key = 'form_' + field['key']
|
| 56 |
+
if field['nature'] == 'radio':
|
| 57 |
+
st.radio(
|
| 58 |
+
field['label'],
|
| 59 |
+
field['options'],
|
| 60 |
+
index=field['options'].index(field.get('value')) if field.get('value') in field['options'] else 0,
|
| 61 |
+
key=key,
|
| 62 |
+
on_change=update_session_state,
|
| 63 |
+
args=(key,)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
elif field['nature'] == 'selectbox':
|
| 67 |
+
st.selectbox(
|
| 68 |
+
field['label'],
|
| 69 |
+
field['options'],
|
| 70 |
+
index=field['options'].index(field.get('value')) if field.get('value', []) in field['options'] else 0,
|
| 71 |
+
key=key,
|
| 72 |
+
on_change=update_session_state,
|
| 73 |
+
args=(key,)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
elif field['nature'] == 'multiselect':
|
| 77 |
+
default_values = field.get('value', [])
|
| 78 |
+
|
| 79 |
+
st.multiselect(
|
| 80 |
+
field['label'],
|
| 81 |
+
field['options'],
|
| 82 |
+
default=default_values if default_values else None,
|
| 83 |
+
key=key,
|
| 84 |
+
on_change=update_session_state,
|
| 85 |
+
args=(key,)
|
| 86 |
+
)
|
| 87 |
+
elif field['nature'] == 'date':
|
| 88 |
+
st.date_input(
|
| 89 |
+
field['label'],
|
| 90 |
+
value=datetime.date.fromisoformat("2011-09-20"),
|
| 91 |
+
key=key,
|
| 92 |
+
on_change=update_session_state,
|
| 93 |
+
args=(key,)
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
elif field['nature'] == 'numeric':
|
| 97 |
+
st.number_input(field['label'],
|
| 98 |
+
value=field.get('value', 0),
|
| 99 |
+
key=key,
|
| 100 |
+
on_change=update_session_state,
|
| 101 |
+
args=(key,)
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
elif field['nature'] == 'text_area':
|
| 105 |
+
st.text_area(field['label'],
|
| 106 |
+
value=field.get('value', ""),
|
| 107 |
+
key=key,
|
| 108 |
+
on_change=update_session_state,
|
| 109 |
+
args=(key,)
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
elif field['nature'] == 'slider':
|
| 113 |
+
st.slider(field['label'],
|
| 114 |
+
value=field.get('value', [0, 1000]),
|
| 115 |
+
min_value=field.get('min', 0), # Valeur minimale du slider
|
| 116 |
+
max_value=field.get('max', 5000), # Valeur maximale du slider
|
| 117 |
+
step=field.get('step', 500),
|
| 118 |
+
key=key,
|
| 119 |
+
on_change=update_session_state,
|
| 120 |
+
args=(key,)
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
else:
|
| 124 |
+
st.text_input(label=field['label'],
|
| 125 |
+
value=field.get('value', ""),
|
| 126 |
+
key=key,
|
| 127 |
+
on_change=update_session_state,
|
| 128 |
+
args=(key,)
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
page()
|
pages/cettons.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from util import getYamlConfig
|
| 4 |
+
|
| 5 |
+
company_code = "cettons_"
|
| 6 |
+
|
| 7 |
+
def update_session_state(key,):
|
| 8 |
+
# Get new value from session state and change key for save it in params
|
| 9 |
+
new_value = st.session_state[key]
|
| 10 |
+
key = key[5:]
|
| 11 |
+
|
| 12 |
+
for item in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 13 |
+
if item['key'] == key:
|
| 14 |
+
item['value'] = new_value
|
| 15 |
+
break
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def page():
|
| 19 |
+
st.subheader("Définissez vos paramètres")
|
| 20 |
+
st.text("L'ensemble des critères sont facultatifs.")
|
| 21 |
+
|
| 22 |
+
st.session_state["company_code"] = company_code
|
| 23 |
+
company_config = None
|
| 24 |
+
|
| 25 |
+
# Charge la configuration YAML
|
| 26 |
+
config = getYamlConfig()
|
| 27 |
+
|
| 28 |
+
for company in config['companies']:
|
| 29 |
+
if company['code'] == st.session_state["company_code"]:
|
| 30 |
+
company_config = company
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Vérifie si la structure inclut des 'parts' ou une liste de variables
|
| 34 |
+
if 'parts' in company_config['variables']:
|
| 35 |
+
# Cas avec 'parts' : Trie les parts et affiche les champs par onglet
|
| 36 |
+
parts = company_config["variables"]["parts"]
|
| 37 |
+
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf')))
|
| 38 |
+
|
| 39 |
+
# Création de tabs pour chaque 'part' trié
|
| 40 |
+
tabs = st.tabs([part['name'] for part in parts_sorted])
|
| 41 |
+
for part, tab in zip(parts_sorted, tabs):
|
| 42 |
+
with tab:
|
| 43 |
+
for field in part['fields']:
|
| 44 |
+
for field_session in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 45 |
+
if field['key'] == field_session['key']:
|
| 46 |
+
display_field(field_session)
|
| 47 |
+
else:
|
| 48 |
+
# Display fields directly if no parts are defined
|
| 49 |
+
for field in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 50 |
+
display_field(field)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def display_field(field):
|
| 54 |
+
"""Helper function to create the correct input based on field 'nature'."""
|
| 55 |
+
key = 'form_' + field['key']
|
| 56 |
+
if field['nature'] == 'radio':
|
| 57 |
+
st.radio(
|
| 58 |
+
field['label'],
|
| 59 |
+
field['options'],
|
| 60 |
+
index=field['options'].index(field.get('value')) if field.get('value') in field['options'] else 0,
|
| 61 |
+
key=key,
|
| 62 |
+
on_change=update_session_state,
|
| 63 |
+
args=(key,)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
elif field['nature'] == 'selectbox':
|
| 67 |
+
st.selectbox(
|
| 68 |
+
field['label'],
|
| 69 |
+
field['options'],
|
| 70 |
+
index=field['options'].index(field.get('value')) if field.get('value', []) in field['options'] else 0,
|
| 71 |
+
key=key,
|
| 72 |
+
on_change=update_session_state,
|
| 73 |
+
args=(key,)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
elif field['nature'] == 'multiselect':
|
| 77 |
+
default_values = field.get('value', [])
|
| 78 |
+
|
| 79 |
+
st.multiselect(
|
| 80 |
+
field['label'],
|
| 81 |
+
field['options'],
|
| 82 |
+
default=default_values if default_values else None,
|
| 83 |
+
key=key,
|
| 84 |
+
on_change=update_session_state,
|
| 85 |
+
args=(key,)
|
| 86 |
+
)
|
| 87 |
+
elif field['nature'] == 'date':
|
| 88 |
+
st.date_input(
|
| 89 |
+
field['label'],
|
| 90 |
+
value=datetime.date.fromisoformat("2021-03-29"),
|
| 91 |
+
key=key,
|
| 92 |
+
on_change=update_session_state,
|
| 93 |
+
args=(key,)
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
elif field['nature'] == 'numeric':
|
| 97 |
+
st.number_input(field['label'],
|
| 98 |
+
value=field.get('value', 0),
|
| 99 |
+
key=key,
|
| 100 |
+
on_change=update_session_state,
|
| 101 |
+
args=(key,)
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
elif field['nature'] == 'text_area':
|
| 105 |
+
st.text_area(field['label'],
|
| 106 |
+
value=field.get('value', ""),
|
| 107 |
+
key=key,
|
| 108 |
+
on_change=update_session_state,
|
| 109 |
+
args=(key,)
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
elif field['nature'] == 'slider':
|
| 113 |
+
st.slider(field['label'],
|
| 114 |
+
value=field.get('value', [0, 1000]),
|
| 115 |
+
min_value=field.get('min', 0), # Valeur minimale du slider
|
| 116 |
+
max_value=field.get('max', 5000), # Valeur maximale du slider
|
| 117 |
+
step=field.get('step', 500),
|
| 118 |
+
key=key,
|
| 119 |
+
on_change=update_session_state,
|
| 120 |
+
args=(key,)
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
else:
|
| 124 |
+
st.text_input(label=field['label'],
|
| 125 |
+
value=field.get('value', ""),
|
| 126 |
+
key=key,
|
| 127 |
+
on_change=update_session_state,
|
| 128 |
+
args=(key,)
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
page()
|
pages/chatbot_afp.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from model import selector
|
| 5 |
+
from util import getYamlConfig
|
| 6 |
+
from st_copy_to_clipboard import st_copy_to_clipboard
|
| 7 |
+
from subscription.index import is_usage_limit_reached, daily_limit_enabled
|
| 8 |
+
|
| 9 |
+
def display_messages():
|
| 10 |
+
|
| 11 |
+
for i, message in enumerate(st.session_state.chat_history):
|
| 12 |
+
if isinstance(message, AIMessage):
|
| 13 |
+
with st.chat_message("AI"):
|
| 14 |
+
# Display the model from the kwargs
|
| 15 |
+
model = message.kwargs.get("model", "Unknown Model") # Get the model, default to "Unknown Model"
|
| 16 |
+
st.write(f"**Model :** {model}")
|
| 17 |
+
st.markdown(message.content)
|
| 18 |
+
st_copy_to_clipboard(message.content,key=f"message_{i}")
|
| 19 |
+
# show_retrieved_documents(st.session_state.chat_history[i-1].content)
|
| 20 |
+
|
| 21 |
+
elif isinstance(message, HumanMessage):
|
| 22 |
+
with st.chat_message("Moi"):
|
| 23 |
+
st.write(message.content)
|
| 24 |
+
|
| 25 |
+
elif isinstance(message, SystemMessage):
|
| 26 |
+
with st.chat_message("System"):
|
| 27 |
+
st.write(message.content)
|
| 28 |
+
|
| 29 |
+
def show_retrieved_documents(query: str = ''):
|
| 30 |
+
if query == '':
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
# Créer l'expander pour les documents trouvés
|
| 34 |
+
expander = st.expander("Documents trouvés")
|
| 35 |
+
|
| 36 |
+
# Boucler à travers les documents récupérés
|
| 37 |
+
for item in st.session_state.get("retrived_documents", []):
|
| 38 |
+
if 'query' in item:
|
| 39 |
+
if item["query"] == query:
|
| 40 |
+
for doc in item.get("documents", []):
|
| 41 |
+
expander.write(doc["metadata"]["source"])
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def launchQuery(query: str = None):
|
| 45 |
+
|
| 46 |
+
# Initialize the assistant's response
|
| 47 |
+
full_response = st.write_stream(
|
| 48 |
+
st.session_state["assistant"].ask(
|
| 49 |
+
query,
|
| 50 |
+
# prompt_system=st.session_state.prompt_system,
|
| 51 |
+
messages=st.session_state["chat_history"] if "chat_history" in st.session_state else [],
|
| 52 |
+
variables=st.session_state["data_dict"]
|
| 53 |
+
))
|
| 54 |
+
|
| 55 |
+
# Temporary placeholder AI message in chat history
|
| 56 |
+
st.session_state["chat_history"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
|
| 57 |
+
st.rerun()
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def show_prompts():
|
| 61 |
+
yaml_data = getYamlConfig()["prompts"]
|
| 62 |
+
|
| 63 |
+
expander = st.expander("Prompts pré-définis")
|
| 64 |
+
|
| 65 |
+
for categroy in yaml_data:
|
| 66 |
+
expander.write(categroy.capitalize())
|
| 67 |
+
|
| 68 |
+
for item in yaml_data[categroy]:
|
| 69 |
+
if expander.button(item, key=f"button_{item}"):
|
| 70 |
+
launchQuery(item)
|
| 71 |
+
|
| 72 |
+
def remplir_texte(texte: str, variables: dict, remove_line_if_unspecified: bool = False) -> str:
|
| 73 |
+
# Convertir les valeurs en chaînes de caractères pour éviter les erreurs avec format()
|
| 74 |
+
variables_str = {
|
| 75 |
+
key: (', '.join(value) if isinstance(value, list) and len(value) else value if value else 'Non spécifié')
|
| 76 |
+
for key, value in variables.items()
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
# Remplacer les variables dynamiques dans le texte
|
| 80 |
+
try:
|
| 81 |
+
texte_rempli = texte.format(**variables_str)
|
| 82 |
+
except KeyError as e:
|
| 83 |
+
raise ValueError(f"Clé manquante dans le dictionnaire : {e}")
|
| 84 |
+
|
| 85 |
+
# Supprimer les lignes contenant "Non spécifié" si l'option est activée
|
| 86 |
+
if remove_line_if_unspecified:
|
| 87 |
+
lignes = texte_rempli.split('\n')
|
| 88 |
+
lignes = [ligne for ligne in lignes if 'Non spécifié' not in ligne]
|
| 89 |
+
texte_rempli = '\n'.join(lignes)
|
| 90 |
+
|
| 91 |
+
return texte_rempli
|
| 92 |
+
|
| 93 |
+
def page():
|
| 94 |
+
st.subheader("Auto France Parts")
|
| 95 |
+
|
| 96 |
+
company_code = "afp_"
|
| 97 |
+
|
| 98 |
+
if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) <= 2:
|
| 99 |
+
# print("Initialisation de l'historique")
|
| 100 |
+
if st.session_state["data_dict"][company_code] is not None:
|
| 101 |
+
# Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
|
| 102 |
+
vars = {item['key']: item['value'] for item in st.session_state["data_dict"][company_code] if 'key' in item and 'value' in item}
|
| 103 |
+
|
| 104 |
+
system_template = st.session_state.prompt_system
|
| 105 |
+
full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
|
| 106 |
+
|
| 107 |
+
st.session_state["chat_history"] = [
|
| 108 |
+
SystemMessage(content=full),
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
if "assistant" not in st.session_state:
|
| 112 |
+
st.text("Assistant non initialisé")
|
| 113 |
+
|
| 114 |
+
st.markdown("<style>iframe{height:50px;}</style>", unsafe_allow_html=True)
|
| 115 |
+
|
| 116 |
+
# Collpase for default prompts
|
| 117 |
+
show_prompts()
|
| 118 |
+
|
| 119 |
+
# Models selector
|
| 120 |
+
selector.ModelSelector()
|
| 121 |
+
|
| 122 |
+
if(len(st.session_state["chat_history"])):
|
| 123 |
+
if st.button("Effacer l'historique"):
|
| 124 |
+
st.session_state["chat_history"] = []
|
| 125 |
+
|
| 126 |
+
# Displaying messages
|
| 127 |
+
display_messages()
|
| 128 |
+
|
| 129 |
+
message = ""
|
| 130 |
+
reached = False
|
| 131 |
+
|
| 132 |
+
if daily_limit_enabled():
|
| 133 |
+
reached = is_usage_limit_reached()
|
| 134 |
+
if reached:
|
| 135 |
+
message = "Vous avez atteint la limite quotidienne de messages."
|
| 136 |
+
|
| 137 |
+
user_query = st.chat_input(message, disabled=reached)
|
| 138 |
+
|
| 139 |
+
if user_query is not None and user_query != "":
|
| 140 |
+
|
| 141 |
+
st.session_state["chat_history"].append(HumanMessage(content=user_query))
|
| 142 |
+
|
| 143 |
+
# Stream and display response
|
| 144 |
+
launchQuery(user_query)
|
| 145 |
+
|
| 146 |
+
# DOnnes moi la liste des 3 meilleures subventions. Uniquement le nom des subventions
|
| 147 |
+
page()
|
pages/chatbot_cettons.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from model import selector
|
| 5 |
+
from util import getYamlConfig
|
| 6 |
+
from st_copy_to_clipboard import st_copy_to_clipboard
|
| 7 |
+
from subscription.index import is_usage_limit_reached, daily_limit_enabled
|
| 8 |
+
|
| 9 |
+
def display_messages():
|
| 10 |
+
|
| 11 |
+
for i, message in enumerate(st.session_state.chat_history):
|
| 12 |
+
if isinstance(message, AIMessage):
|
| 13 |
+
with st.chat_message("AI"):
|
| 14 |
+
# Display the model from the kwargs
|
| 15 |
+
model = message.kwargs.get("model", "Unknown Model") # Get the model, default to "Unknown Model"
|
| 16 |
+
st.write(f"**Model :** {model}")
|
| 17 |
+
st.markdown(message.content)
|
| 18 |
+
st_copy_to_clipboard(message.content,key=f"message_{i}")
|
| 19 |
+
# show_retrieved_documents(st.session_state.chat_history[i-1].content)
|
| 20 |
+
|
| 21 |
+
elif isinstance(message, HumanMessage):
|
| 22 |
+
with st.chat_message("Moi"):
|
| 23 |
+
st.write(message.content)
|
| 24 |
+
|
| 25 |
+
elif isinstance(message, SystemMessage):
|
| 26 |
+
with st.chat_message("System"):
|
| 27 |
+
st.write(message.content)
|
| 28 |
+
|
| 29 |
+
def show_retrieved_documents(query: str = ''):
|
| 30 |
+
if query == '':
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
# Créer l'expander pour les documents trouvés
|
| 34 |
+
expander = st.expander("Documents trouvés")
|
| 35 |
+
|
| 36 |
+
# Boucler à travers les documents récupérés
|
| 37 |
+
for item in st.session_state.get("retrived_documents", []):
|
| 38 |
+
if 'query' in item:
|
| 39 |
+
if item["query"] == query:
|
| 40 |
+
for doc in item.get("documents", []):
|
| 41 |
+
expander.write(doc["metadata"]["source"])
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def launchQuery(query: str = None):
|
| 45 |
+
|
| 46 |
+
# Initialize the assistant's response
|
| 47 |
+
full_response = st.write_stream(
|
| 48 |
+
st.session_state["assistant"].ask(
|
| 49 |
+
query,
|
| 50 |
+
# prompt_system=st.session_state.prompt_system,
|
| 51 |
+
messages=st.session_state["chat_history"] if "chat_history" in st.session_state else [],
|
| 52 |
+
variables=st.session_state["data_dict"]
|
| 53 |
+
))
|
| 54 |
+
|
| 55 |
+
# Temporary placeholder AI message in chat history
|
| 56 |
+
st.session_state["chat_history"].append(AIMessage(content=full_response, kwargs={"model": st.session_state["assistant"].getReadableModel()}))
|
| 57 |
+
st.rerun()
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def show_prompts():
|
| 61 |
+
yaml_data = getYamlConfig()["prompts"]
|
| 62 |
+
|
| 63 |
+
expander = st.expander("Prompts pré-définis")
|
| 64 |
+
|
| 65 |
+
for categroy in yaml_data:
|
| 66 |
+
expander.write(categroy.capitalize())
|
| 67 |
+
|
| 68 |
+
for item in yaml_data[categroy]:
|
| 69 |
+
if expander.button(item, key=f"button_{item}"):
|
| 70 |
+
launchQuery(item)
|
| 71 |
+
|
| 72 |
+
def remplir_texte(texte: str, variables: dict, remove_line_if_unspecified: bool = False) -> str:
|
| 73 |
+
# Convertir les valeurs en chaînes de caractères pour éviter les erreurs avec format()
|
| 74 |
+
variables_str = {
|
| 75 |
+
key: (', '.join(value) if isinstance(value, list) and len(value) else value if value else 'Non spécifié')
|
| 76 |
+
for key, value in variables.items()
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
# Remplacer les variables dynamiques dans le texte
|
| 80 |
+
try:
|
| 81 |
+
texte_rempli = texte.format(**variables_str)
|
| 82 |
+
except KeyError as e:
|
| 83 |
+
raise ValueError(f"Clé manquante dans le dictionnaire : {e}")
|
| 84 |
+
|
| 85 |
+
# Supprimer les lignes contenant "Non spécifié" si l'option est activée
|
| 86 |
+
if remove_line_if_unspecified:
|
| 87 |
+
lignes = texte_rempli.split('\n')
|
| 88 |
+
lignes = [ligne for ligne in lignes if 'Non spécifié' not in ligne]
|
| 89 |
+
texte_rempli = '\n'.join(lignes)
|
| 90 |
+
|
| 91 |
+
return texte_rempli
|
| 92 |
+
|
| 93 |
+
def page():
|
| 94 |
+
st.subheader("La Pyramide des Cettons")
|
| 95 |
+
|
| 96 |
+
company_code = "cettons_"
|
| 97 |
+
|
| 98 |
+
if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) <= 2:
|
| 99 |
+
# print("Initialisation de l'historique")
|
| 100 |
+
if st.session_state["data_dict"][company_code] is not None:
|
| 101 |
+
# Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
|
| 102 |
+
vars = {item['key']: item['value'] for item in st.session_state["data_dict"][company_code] if 'key' in item and 'value' in item}
|
| 103 |
+
|
| 104 |
+
system_template = st.session_state.prompt_system
|
| 105 |
+
full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
|
| 106 |
+
|
| 107 |
+
st.session_state["chat_history"] = [
|
| 108 |
+
SystemMessage(content=full),
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
if "assistant" not in st.session_state:
|
| 112 |
+
st.text("Assistant non initialisé")
|
| 113 |
+
|
| 114 |
+
st.markdown("<style>iframe{height:50px;}</style>", unsafe_allow_html=True)
|
| 115 |
+
|
| 116 |
+
# Collpase for default prompts
|
| 117 |
+
show_prompts()
|
| 118 |
+
|
| 119 |
+
# Models selector
|
| 120 |
+
selector.ModelSelector()
|
| 121 |
+
|
| 122 |
+
if(len(st.session_state["chat_history"])):
|
| 123 |
+
if st.button("Effacer l'historique"):
|
| 124 |
+
st.session_state["chat_history"] = []
|
| 125 |
+
|
| 126 |
+
# Displaying messages
|
| 127 |
+
display_messages()
|
| 128 |
+
|
| 129 |
+
message = ""
|
| 130 |
+
reached = False
|
| 131 |
+
|
| 132 |
+
if daily_limit_enabled():
|
| 133 |
+
reached = is_usage_limit_reached()
|
| 134 |
+
if reached:
|
| 135 |
+
message = "Vous avez atteint la limite quotidienne de messages."
|
| 136 |
+
|
| 137 |
+
user_query = st.chat_input(message, disabled=reached)
|
| 138 |
+
|
| 139 |
+
if user_query is not None and user_query != "":
|
| 140 |
+
|
| 141 |
+
st.session_state["chat_history"].append(HumanMessage(content=user_query))
|
| 142 |
+
|
| 143 |
+
# Stream and display response
|
| 144 |
+
launchQuery(user_query)
|
| 145 |
+
|
| 146 |
+
# DOnnes moi la liste des 3 meilleures subventions. Uniquement le nom des subventions
|
| 147 |
+
page()
|
pages/{chatbot.py → chatbot_steel.py}
RENAMED
|
@@ -91,16 +91,15 @@ def remplir_texte(texte: str, variables: dict, remove_line_if_unspecified: bool
|
|
| 91 |
return texte_rempli
|
| 92 |
|
| 93 |
def page():
|
| 94 |
-
st.subheader("
|
| 95 |
|
| 96 |
-
|
| 97 |
-
st.text("Assistant non initialisé")
|
| 98 |
|
| 99 |
-
if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) < 2:
|
| 100 |
-
|
| 101 |
-
if st.session_state["data_dict"] is not None:
|
| 102 |
# Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
|
| 103 |
-
vars = {item['key']: item['value'] for item in st.session_state["data_dict"] if 'key' in item and 'value' in item}
|
| 104 |
|
| 105 |
system_template = st.session_state.prompt_system
|
| 106 |
full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
|
|
@@ -109,6 +108,9 @@ def page():
|
|
| 109 |
SystemMessage(content=full),
|
| 110 |
]
|
| 111 |
|
|
|
|
|
|
|
|
|
|
| 112 |
st.markdown("<style>iframe{height:50px;}</style>", unsafe_allow_html=True)
|
| 113 |
|
| 114 |
# Collpase for default prompts
|
|
@@ -141,5 +143,5 @@ def page():
|
|
| 141 |
# Stream and display response
|
| 142 |
launchQuery(user_query)
|
| 143 |
|
| 144 |
-
|
| 145 |
page()
|
|
|
|
| 91 |
return texte_rempli
|
| 92 |
|
| 93 |
def page():
|
| 94 |
+
st.subheader("Steel France")
|
| 95 |
|
| 96 |
+
company_code = "steel_"
|
|
|
|
| 97 |
|
| 98 |
+
if "chat_history" not in st.session_state or len(st.session_state["chat_history"]) <= 2:
|
| 99 |
+
# print("Initialisation de l'historique")
|
| 100 |
+
if st.session_state["data_dict"][company_code] is not None:
|
| 101 |
# Convertir la liste en dictionnaire avec 'key' comme clé et 'value' comme valeur
|
| 102 |
+
vars = {item['key']: item['value'] for item in st.session_state["data_dict"][company_code] if 'key' in item and 'value' in item}
|
| 103 |
|
| 104 |
system_template = st.session_state.prompt_system
|
| 105 |
full = remplir_texte(system_template, vars, st.session_state["remove_undefined_value"])
|
|
|
|
| 108 |
SystemMessage(content=full),
|
| 109 |
]
|
| 110 |
|
| 111 |
+
if "assistant" not in st.session_state:
|
| 112 |
+
st.text("Assistant non initialisé")
|
| 113 |
+
|
| 114 |
st.markdown("<style>iframe{height:50px;}</style>", unsafe_allow_html=True)
|
| 115 |
|
| 116 |
# Collpase for default prompts
|
|
|
|
| 143 |
# Stream and display response
|
| 144 |
launchQuery(user_query)
|
| 145 |
|
| 146 |
+
# DOnnes moi la liste des 3 meilleures subventions. Uniquement le nom des subventions
|
| 147 |
page()
|
pages/form.py
CHANGED
|
@@ -7,7 +7,7 @@ def update_session_state(key,):
|
|
| 7 |
new_value = st.session_state[key]
|
| 8 |
key = key[5:]
|
| 9 |
|
| 10 |
-
for item in st.session_state
|
| 11 |
if item['key'] == key:
|
| 12 |
item['value'] = new_value
|
| 13 |
break
|
|
@@ -15,16 +15,26 @@ def update_session_state(key,):
|
|
| 15 |
|
| 16 |
def page():
|
| 17 |
st.subheader("Définissez vos paramètres")
|
| 18 |
-
|
| 19 |
st.text("L'ensemble des critères sont facultatifs.")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Charge la configuration YAML
|
| 22 |
config = getYamlConfig()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
|
|
|
|
|
|
| 24 |
# Vérifie si la structure inclut des 'parts' ou une liste de variables
|
| 25 |
-
if 'parts' in
|
| 26 |
# Cas avec 'parts' : Trie les parts et affiche les champs par onglet
|
| 27 |
-
parts =
|
| 28 |
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf')))
|
| 29 |
|
| 30 |
# Création de tabs pour chaque 'part' trié
|
|
@@ -32,12 +42,12 @@ def page():
|
|
| 32 |
for part, tab in zip(parts_sorted, tabs):
|
| 33 |
with tab:
|
| 34 |
for field in part['fields']:
|
| 35 |
-
for field_session in st.session_state
|
| 36 |
if field['key'] == field_session['key']:
|
| 37 |
display_field(field_session)
|
| 38 |
else:
|
| 39 |
# Display fields directly if no parts are defined
|
| 40 |
-
for field in st.session_state
|
| 41 |
display_field(field)
|
| 42 |
|
| 43 |
|
|
|
|
| 7 |
new_value = st.session_state[key]
|
| 8 |
key = key[5:]
|
| 9 |
|
| 10 |
+
for item in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 11 |
if item['key'] == key:
|
| 12 |
item['value'] = new_value
|
| 13 |
break
|
|
|
|
| 15 |
|
| 16 |
def page():
|
| 17 |
st.subheader("Définissez vos paramètres")
|
|
|
|
| 18 |
st.text("L'ensemble des critères sont facultatifs.")
|
| 19 |
|
| 20 |
+
st.session_state["company_code"] = "steel_"
|
| 21 |
+
company_config = None
|
| 22 |
+
|
| 23 |
# Charge la configuration YAML
|
| 24 |
config = getYamlConfig()
|
| 25 |
+
|
| 26 |
+
for company in config['companies']:
|
| 27 |
+
print(f"{company['code']} = {st.session_state["company_code"]}")
|
| 28 |
+
if company['code'] == st.session_state["company_code"]:
|
| 29 |
+
print("ok")
|
| 30 |
+
company_config = company
|
| 31 |
|
| 32 |
+
print(company_config)
|
| 33 |
+
|
| 34 |
# Vérifie si la structure inclut des 'parts' ou une liste de variables
|
| 35 |
+
if 'parts' in company_config['variables']:
|
| 36 |
# Cas avec 'parts' : Trie les parts et affiche les champs par onglet
|
| 37 |
+
parts = company_config["variables"]["parts"]
|
| 38 |
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf')))
|
| 39 |
|
| 40 |
# Création de tabs pour chaque 'part' trié
|
|
|
|
| 42 |
for part, tab in zip(parts_sorted, tabs):
|
| 43 |
with tab:
|
| 44 |
for field in part['fields']:
|
| 45 |
+
for field_session in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 46 |
if field['key'] == field_session['key']:
|
| 47 |
display_field(field_session)
|
| 48 |
else:
|
| 49 |
# Display fields directly if no parts are defined
|
| 50 |
+
for field in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 51 |
display_field(field)
|
| 52 |
|
| 53 |
|
pages/steel.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from util import getYamlConfig
|
| 4 |
+
|
| 5 |
+
company_code = "steel_"
|
| 6 |
+
|
| 7 |
+
def update_session_state(key,):
|
| 8 |
+
# Get new value from session state and change key for save it in params
|
| 9 |
+
new_value = st.session_state[key]
|
| 10 |
+
key = key[5:]
|
| 11 |
+
|
| 12 |
+
for item in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 13 |
+
if item['key'] == key:
|
| 14 |
+
item['value'] = new_value
|
| 15 |
+
break
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def page():
|
| 19 |
+
st.subheader("Définissez vos paramètres")
|
| 20 |
+
st.text("L'ensemble des critères sont facultatifs.")
|
| 21 |
+
|
| 22 |
+
st.session_state["company_code"] = company_code
|
| 23 |
+
company_config = None
|
| 24 |
+
|
| 25 |
+
# Charge la configuration YAML
|
| 26 |
+
config = getYamlConfig()
|
| 27 |
+
|
| 28 |
+
for company in config['companies']:
|
| 29 |
+
if company['code'] == st.session_state["company_code"]:
|
| 30 |
+
company_config = company
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Vérifie si la structure inclut des 'parts' ou une liste de variables
|
| 34 |
+
if 'parts' in company_config['variables']:
|
| 35 |
+
# Cas avec 'parts' : Trie les parts et affiche les champs par onglet
|
| 36 |
+
parts = company_config["variables"]["parts"]
|
| 37 |
+
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf')))
|
| 38 |
+
|
| 39 |
+
# Création de tabs pour chaque 'part' trié
|
| 40 |
+
tabs = st.tabs([part['name'] for part in parts_sorted])
|
| 41 |
+
for part, tab in zip(parts_sorted, tabs):
|
| 42 |
+
with tab:
|
| 43 |
+
for field in part['fields']:
|
| 44 |
+
for field_session in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 45 |
+
if field['key'] == field_session['key']:
|
| 46 |
+
display_field(field_session)
|
| 47 |
+
else:
|
| 48 |
+
# Display fields directly if no parts are defined
|
| 49 |
+
for field in st.session_state["data_dict"][st.session_state["company_code"]]:
|
| 50 |
+
display_field(field)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def display_field(field):
|
| 54 |
+
"""Helper function to create the correct input based on field 'nature'."""
|
| 55 |
+
key = 'form_' + field['key']
|
| 56 |
+
if field['nature'] == 'radio':
|
| 57 |
+
st.radio(
|
| 58 |
+
field['label'],
|
| 59 |
+
field['options'],
|
| 60 |
+
index=field['options'].index(field.get('value')) if field.get('value') in field['options'] else 0,
|
| 61 |
+
key=key,
|
| 62 |
+
on_change=update_session_state,
|
| 63 |
+
args=(key,)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
elif field['nature'] == 'selectbox':
|
| 67 |
+
st.selectbox(
|
| 68 |
+
field['label'],
|
| 69 |
+
field['options'],
|
| 70 |
+
index=field['options'].index(field.get('value')) if field.get('value', []) in field['options'] else 0,
|
| 71 |
+
key=key,
|
| 72 |
+
on_change=update_session_state,
|
| 73 |
+
args=(key,)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
elif field['nature'] == 'multiselect':
|
| 77 |
+
default_values = field.get('value', [])
|
| 78 |
+
|
| 79 |
+
st.multiselect(
|
| 80 |
+
field['label'],
|
| 81 |
+
field['options'],
|
| 82 |
+
default=default_values if default_values else None,
|
| 83 |
+
key=key,
|
| 84 |
+
on_change=update_session_state,
|
| 85 |
+
args=(key,)
|
| 86 |
+
)
|
| 87 |
+
elif field['nature'] == 'date':
|
| 88 |
+
st.date_input(
|
| 89 |
+
field['label'],
|
| 90 |
+
value=datetime.date.fromisoformat("2011-09-20"),
|
| 91 |
+
key=key,
|
| 92 |
+
on_change=update_session_state,
|
| 93 |
+
args=(key,)
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
elif field['nature'] == 'numeric':
|
| 97 |
+
st.number_input(field['label'],
|
| 98 |
+
value=field.get('value', 0),
|
| 99 |
+
key=key,
|
| 100 |
+
on_change=update_session_state,
|
| 101 |
+
args=(key,)
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
elif field['nature'] == 'text_area':
|
| 105 |
+
st.text_area(field['label'],
|
| 106 |
+
value=field.get('value', ""),
|
| 107 |
+
key=key,
|
| 108 |
+
on_change=update_session_state,
|
| 109 |
+
args=(key,)
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
elif field['nature'] == 'slider':
|
| 113 |
+
st.slider(field['label'],
|
| 114 |
+
value=field.get('value', [0, 1000]),
|
| 115 |
+
min_value=field.get('min', 0), # Valeur minimale du slider
|
| 116 |
+
max_value=field.get('max', 5000), # Valeur maximale du slider
|
| 117 |
+
step=field.get('step', 500),
|
| 118 |
+
key=key,
|
| 119 |
+
on_change=update_session_state,
|
| 120 |
+
args=(key,)
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
else:
|
| 124 |
+
st.text_input(label=field['label'],
|
| 125 |
+
value=field.get('value', ""),
|
| 126 |
+
key=key,
|
| 127 |
+
on_change=update_session_state,
|
| 128 |
+
args=(key,)
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
page()
|