Commit
·
ce8e938
1
Parent(s):
7676537
Update stack
Browse files- app.py +12 -1
- config.yaml +6 -10
- pages/form.py +45 -7
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -27,6 +27,17 @@ def init_app():
|
|
| 27 |
st.session_state["data_dict"] = config['variables']
|
| 28 |
st.session_state["prompt_system"] = config['prompt_system']
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def main():
|
| 32 |
|
|
@@ -63,4 +74,4 @@ def main():
|
|
| 63 |
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
-
main()
|
|
|
|
| 27 |
st.session_state["data_dict"] = config['variables']
|
| 28 |
st.session_state["prompt_system"] = config['prompt_system']
|
| 29 |
|
| 30 |
+
if 'parts' in config['variables']:
|
| 31 |
+
# Flatten structure by adding part name to each field
|
| 32 |
+
st.session_state["data_dict"] = [
|
| 33 |
+
{**field, "part": part["name"]}
|
| 34 |
+
for part in config["variables"]["parts"]
|
| 35 |
+
for field in part["fields"]
|
| 36 |
+
]
|
| 37 |
+
else:
|
| 38 |
+
# Initialize session state with single list of variables
|
| 39 |
+
st.session_state["data_dict"] = [{**field} for field in config["variables"]]
|
| 40 |
+
|
| 41 |
|
| 42 |
def main():
|
| 43 |
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
+
main()
|
config.yaml
CHANGED
|
@@ -7,15 +7,11 @@ prompts:
|
|
| 7 |
- "Quel est le cout total avec carburant en €/h d'une moissonneuse batteuse avec une coupe de 7,5 m ?"
|
| 8 |
|
| 9 |
variables:
|
| 10 |
-
- label
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
value :
|
| 16 |
-
- label : Mon paramètre 3
|
| 17 |
-
key : param3
|
| 18 |
-
value :
|
| 19 |
|
| 20 |
|
| 21 |
prompt_system: "
|
|
@@ -50,4 +46,4 @@ Document utilisateur : {documentContext}
|
|
| 50 |
|
| 51 |
Voici l'historique des messages : {messages}
|
| 52 |
La demande de l'utilisateur est : {query}
|
| 53 |
-
"
|
|
|
|
| 7 |
- "Quel est le cout total avec carburant en €/h d'une moissonneuse batteuse avec une coupe de 7,5 m ?"
|
| 8 |
|
| 9 |
variables:
|
| 10 |
+
- label: "Région viticole"
|
| 11 |
+
nature: 'radio'
|
| 12 |
+
key: param1
|
| 13 |
+
options: ["Champagne", "Vin de Bordeaux", "Occitanie"]
|
| 14 |
+
value: # Valeur par défaut
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
prompt_system: "
|
|
|
|
| 46 |
|
| 47 |
Voici l'historique des messages : {messages}
|
| 48 |
La demande de l'utilisateur est : {query}
|
| 49 |
+
"
|
pages/form.py
CHANGED
|
@@ -1,14 +1,52 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
def page():
|
| 4 |
st.subheader("Définissez vos paramètres")
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from util import getYamlConfig
|
| 3 |
|
| 4 |
def page():
|
| 5 |
st.subheader("Définissez vos paramètres")
|
| 6 |
|
| 7 |
+
# Charge la configuration YAML
|
| 8 |
+
config = getYamlConfig()
|
| 9 |
+
|
| 10 |
+
# Vérifie si la structure inclut des 'parts' ou une liste de variables
|
| 11 |
+
if 'parts' in config['variables']:
|
| 12 |
+
# Cas avec 'parts' : Trie les parts et affiche les champs par onglet
|
| 13 |
+
parts = config["variables"]["parts"]
|
| 14 |
+
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf')))
|
| 15 |
|
| 16 |
+
# Création de tabs pour chaque 'part' trié
|
| 17 |
+
tabs = st.tabs([part['name'] for part in parts_sorted])
|
| 18 |
+
for part, tab in zip(parts_sorted, tabs):
|
| 19 |
+
with tab:
|
| 20 |
+
for field in part['fields']:
|
| 21 |
+
display_field(field)
|
| 22 |
+
else:
|
| 23 |
+
# Display fields directly if no parts are defined
|
| 24 |
+
for field in st.session_state.data_dict:
|
| 25 |
+
display_field(field)
|
| 26 |
|
| 27 |
+
|
| 28 |
+
def display_field(field):
|
| 29 |
+
"""Helper function to create the correct input based on field 'nature'."""
|
| 30 |
+
if field['nature'] == 'radio':
|
| 31 |
+
value = st.radio(field['label'], field['options'], key=field['key'])
|
| 32 |
+
field['value'] = value
|
| 33 |
+
elif field['nature'] == 'selectbox':
|
| 34 |
+
value = st.selectbox(field['label'], field['options'], key=field['key'])
|
| 35 |
+
field['value'] = value
|
| 36 |
+
elif field['nature'] == 'multiselect':
|
| 37 |
+
value = st.multiselect(field['label'], field['options'], key=field['key'])
|
| 38 |
+
field['value'] = value
|
| 39 |
+
elif field['nature'] == 'date':
|
| 40 |
+
value = st.date_input(field['label'], key=field['key'])
|
| 41 |
+
field['value'] = value
|
| 42 |
+
elif field['nature'] == 'numeric':
|
| 43 |
+
value = st.number_input(field['label'], key=field['key'])
|
| 44 |
+
field['value'] = value
|
| 45 |
+
elif field['nature'] == 'text_area':
|
| 46 |
+
value = st.text_area(field['label'], value=field['value'] if 'value' in field else "", key=field['key'])
|
| 47 |
+
field['value'] = value
|
| 48 |
+
else:
|
| 49 |
+
value = st.text_input(label=field['label'], value=field['value'] if 'value' in field else "")
|
| 50 |
+
field['value'] = value
|
| 51 |
+
|
| 52 |
+
page()
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
streamlit==1.37.0
|
|
|
|
| 2 |
streamlit_chat
|
| 3 |
python-dotenv
|
| 4 |
pymupdf
|
|
|
|
| 1 |
streamlit==1.37.0
|
| 2 |
+
faiss-gpu
|
| 3 |
streamlit_chat
|
| 4 |
python-dotenv
|
| 5 |
pymupdf
|