[email protected]
commited on
Commit
·
720c02e
1
Parent(s):
444d7f6
Add logo to app and restructure navigation; introduce YAML configuration for prompts
Browse files- app.py +27 -12
- assets/agir_agri.png +0 -0
- config.yaml +12 -0
- pages/chatbot.py +34 -6
- rag.py +0 -1
app.py
CHANGED
@@ -10,6 +10,7 @@ from vectore_store.VectoreStoreManager import VectoreStoreManager
|
|
10 |
load_dotenv()
|
11 |
|
12 |
GROUP_NAME = os.environ.get("APP_NAME")
|
|
|
13 |
|
14 |
def init_app():
|
15 |
|
@@ -34,22 +35,36 @@ def main():
|
|
34 |
|
35 |
st.set_page_config(page_title=GROUP_NAME)
|
36 |
|
|
|
37 |
st.title(GROUP_NAME)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
form = st.Page("pages/form.py", title="
|
43 |
-
chatbot = st.Page("pages/chatbot.py", title="Chatbot", icon="
|
44 |
|
45 |
pg = st.navigation(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
)
|
54 |
|
55 |
pg.run()
|
|
|
10 |
load_dotenv()
|
11 |
|
12 |
GROUP_NAME = os.environ.get("APP_NAME")
|
13 |
+
LOGO = "assets/agir_agri.png"
|
14 |
|
15 |
def init_app():
|
16 |
|
|
|
35 |
|
36 |
st.set_page_config(page_title=GROUP_NAME)
|
37 |
|
38 |
+
st.logo(LOGO)
|
39 |
st.title(GROUP_NAME)
|
40 |
|
41 |
+
saved_documents = st.Page("pages/persistent_documents.py", title="Communs", icon="🗃️")
|
42 |
+
documents = st.Page("pages/documents.py", title="Vos documents", icon="📂")
|
43 |
+
prompt_system = st.Page("pages/prompt_system.py", title="Prompt système", icon="🖊️", default=True)
|
44 |
+
form = st.Page("pages/form.py", title="Paramètres", icon="📋")
|
45 |
+
chatbot = st.Page("pages/chatbot.py", title="Chatbot", icon="🤖")
|
46 |
|
47 |
pg = st.navigation(
|
48 |
+
{
|
49 |
+
"Documents": [
|
50 |
+
saved_documents,
|
51 |
+
documents,
|
52 |
+
],
|
53 |
+
"Configurations": [
|
54 |
+
prompt_system,
|
55 |
+
form,
|
56 |
+
],
|
57 |
+
"Dialogue": [
|
58 |
+
chatbot
|
59 |
+
],
|
60 |
+
}
|
61 |
+
# [
|
62 |
+
# saved_documents,
|
63 |
+
# prompt_system,
|
64 |
+
# documents,
|
65 |
+
# form,
|
66 |
+
# chatbot
|
67 |
+
# ]
|
68 |
)
|
69 |
|
70 |
pg.run()
|
assets/agir_agri.png
ADDED
![]() |
config.yaml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
prompts:
|
2 |
+
general:
|
3 |
+
- "Quels sont les principaux défis auxquels les agriculteurs sont confrontés aujourd'hui ?"
|
4 |
+
- "Explique-moi les différences entre l'agriculture biologique et l'agriculture conventionnelle."
|
5 |
+
- "Comment l'agriculture contribue-t-elle à la lutte contre le changement climatique ?"
|
6 |
+
- "Quels sont les avantages et inconvénients des OGM dans l'agriculture ?"
|
7 |
+
|
8 |
+
techniques:
|
9 |
+
- "Comment fonctionne la rotation des cultures et pourquoi est-elle importante ?"
|
10 |
+
- "Explique les avantages de l'irrigation goutte à goutte pour les cultures."
|
11 |
+
- "Quels sont les types de fertilisants les plus utilisés en agriculture et leurs impacts ?"
|
12 |
+
- "Quelles sont les techniques de lutte biologique contre les nuisibles ?"
|
pages/chatbot.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
from streamlit_chat import message
|
3 |
from model import selector
|
4 |
|
@@ -8,32 +10,58 @@ def display_messages():
|
|
8 |
st.session_state["thinking_spinner"] = st.empty()
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def process_input():
|
12 |
-
if st.session_state["user_input"] and len(st.session_state["user_input"].strip()) > 0:
|
13 |
user_text = st.session_state["user_input"].strip()
|
14 |
|
15 |
-
|
16 |
with st.session_state["thinking_spinner"], st.spinner(f"Je réfléchis"):
|
17 |
agent_text = st.session_state["assistant"].ask(user_text, st.session_state["messages"] if "messages" in st.session_state else [], variables=st.session_state["data_dict"])
|
18 |
|
19 |
st.session_state["messages"].append((user_text, True))
|
20 |
st.session_state["messages"].append((agent_text, False))
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def page():
|
24 |
st.subheader("Posez vos questions")
|
25 |
|
26 |
-
|
|
|
27 |
|
28 |
if "assistant" not in st.session_state:
|
29 |
st.text("Assistant non initialisé")
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
st.text("Prompt system : " + prompt_sys)
|
35 |
|
|
|
|
|
|
|
36 |
display_messages()
|
|
|
37 |
st.text_input("Message", key="user_input", on_change=process_input)
|
38 |
|
39 |
page()
|
|
|
1 |
import streamlit as st
|
2 |
+
import yaml
|
3 |
+
import os
|
4 |
from streamlit_chat import message
|
5 |
from model import selector
|
6 |
|
|
|
10 |
st.session_state["thinking_spinner"] = st.empty()
|
11 |
|
12 |
|
13 |
+
# Charger les données YAML
|
14 |
+
def load_yaml(file_path):
|
15 |
+
with open(file_path, 'r') as file:
|
16 |
+
data = yaml.safe_load(file)
|
17 |
+
return data
|
18 |
+
|
19 |
+
|
20 |
def process_input():
|
21 |
+
if "user_input" in st.session_state and st.session_state["user_input"] and len(st.session_state["user_input"].strip()) > 0:
|
22 |
user_text = st.session_state["user_input"].strip()
|
23 |
|
|
|
24 |
with st.session_state["thinking_spinner"], st.spinner(f"Je réfléchis"):
|
25 |
agent_text = st.session_state["assistant"].ask(user_text, st.session_state["messages"] if "messages" in st.session_state else [], variables=st.session_state["data_dict"])
|
26 |
|
27 |
st.session_state["messages"].append((user_text, True))
|
28 |
st.session_state["messages"].append((agent_text, False))
|
29 |
|
30 |
+
@st.dialog("Choisissez votre prompt")
|
31 |
+
def show_prompts():
|
32 |
+
file_path = os.path.join(os.path.dirname(__file__), '..', 'config.yaml')
|
33 |
+
yaml_data = load_yaml(file_path)
|
34 |
+
|
35 |
+
# Boucle à travers les éléments YAML
|
36 |
+
for categroy in yaml_data['prompts']: # Exemple avec la catégorie conversation
|
37 |
+
st.write(categroy.capitalize())
|
38 |
+
|
39 |
+
for item in yaml_data['prompts'][categroy]:
|
40 |
+
if st.button(item, key=f"button_{item}"):
|
41 |
+
st.session_state["user_input"] = item
|
42 |
+
st.rerun()
|
43 |
|
44 |
def page():
|
45 |
st.subheader("Posez vos questions")
|
46 |
|
47 |
+
if "user_input" in st.session_state:
|
48 |
+
process_input()
|
49 |
|
50 |
if "assistant" not in st.session_state:
|
51 |
st.text("Assistant non initialisé")
|
52 |
+
|
53 |
+
# Bouton pour ouvrir la modale
|
54 |
+
if st.button("Prompts pré-définis"):
|
55 |
+
show_prompts()
|
56 |
|
57 |
|
58 |
+
selector.ModelSelector()
|
|
|
|
|
59 |
|
60 |
+
# Get prompt system
|
61 |
+
# prompt_sys = st.session_state.prompt_system if 'prompt_system' in st.session_state and st.session_state.prompt_system != '' else "Renseignez votre prompt system"
|
62 |
+
|
63 |
display_messages()
|
64 |
+
|
65 |
st.text_input("Message", key="user_input", on_change=process_input)
|
66 |
|
67 |
page()
|
rag.py
CHANGED
@@ -72,7 +72,6 @@ class Rag:
|
|
72 |
)
|
73 |
|
74 |
def ask(self, query: str, messages: list, variables: dict = {}):
|
75 |
-
print(self.model)
|
76 |
self.chain = self.prompt | self.model | StrOutputParser()
|
77 |
|
78 |
# Retrieve the context document
|
|
|
72 |
)
|
73 |
|
74 |
def ask(self, query: str, messages: list, variables: dict = {}):
|
|
|
75 |
self.chain = self.prompt | self.model | StrOutputParser()
|
76 |
|
77 |
# Retrieve the context document
|