cdupland
commited on
Commit
·
d9e40cd
1
Parent(s):
e58c122
Add prompts, rag on session + RAG and Prompt
Browse files- RAG_PDF_WEB.py +10 -1
- app.py +18 -4
- data_manager_bziiit.py +16 -0
- prompt.py +68 -0
- session.py +10 -0
RAG_PDF_WEB.py
CHANGED
|
@@ -75,6 +75,9 @@ def rag_pdf_web():
|
|
| 75 |
|
| 76 |
option = st.radio("Source", ("A partir de votre site web", "A partir de vos documents entreprise"))
|
| 77 |
|
|
|
|
|
|
|
|
|
|
| 78 |
if option == "A partir de votre site web":
|
| 79 |
url1 = st.text_input("URL 1")
|
| 80 |
url2 = st.text_input("URL 2")
|
|
@@ -208,4 +211,10 @@ def rag_pdf_web():
|
|
| 208 |
renvoie ta réponse en markdown et bien formatée
|
| 209 |
'''
|
| 210 |
response = chain.invoke(question)
|
| 211 |
-
st.markdown(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
option = st.radio("Source", ("A partir de votre site web", "A partir de vos documents entreprise"))
|
| 77 |
|
| 78 |
+
vectorstore = None
|
| 79 |
+
chain = None
|
| 80 |
+
|
| 81 |
if option == "A partir de votre site web":
|
| 82 |
url1 = st.text_input("URL 1")
|
| 83 |
url2 = st.text_input("URL 2")
|
|
|
|
| 211 |
renvoie ta réponse en markdown et bien formatée
|
| 212 |
'''
|
| 213 |
response = chain.invoke(question)
|
| 214 |
+
st.markdown(response.content)
|
| 215 |
+
|
| 216 |
+
if vectorstore and chain:
|
| 217 |
+
st.success("Le vectorstore et le RAG chain ont été créés avec succès!")
|
| 218 |
+
return vectorstore, chain
|
| 219 |
+
else:
|
| 220 |
+
return None, None
|
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from inspirezvous import *
|
|
| 17 |
from collaborons import display_company_selection_for_materiality,display_materiality_matrix
|
| 18 |
from documentations import display_documentation
|
| 19 |
from RAG_PDF_WEB import rag_pdf_web
|
|
|
|
| 20 |
|
| 21 |
def main():
|
| 22 |
st.markdown(":point_left: Cliquez pour vous inspirer", unsafe_allow_html=True)
|
|
@@ -24,7 +25,8 @@ def main():
|
|
| 24 |
st.sidebar.title("OPEN DATA & IA au service de la RSE")
|
| 25 |
section_principale = st.sidebar.radio(
|
| 26 |
"Choisissez votre section",
|
| 27 |
-
["Data Bordeaux métropole", "Data bziiit","IA RSE","Documentation"]
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
if section_principale == "Data Bordeaux métropole":
|
|
@@ -69,11 +71,13 @@ def main():
|
|
| 69 |
"Matrice de matérialité"
|
| 70 |
]
|
| 71 |
)
|
|
|
|
| 72 |
if ia_mode == "Parties prenantes":
|
| 73 |
data, bziiit_data = fetch_data()
|
| 74 |
selected_company = display_company_selection_for_materiality(data)
|
| 75 |
if selected_company:
|
| 76 |
display_materiality_partiesprenantes(selected_company, data, bziiit_data)
|
|
|
|
| 77 |
elif ia_mode == "Matrice de matérialité":
|
| 78 |
data, bziiit_data = fetch_data()
|
| 79 |
selected_company = display_company_selection_for_materiality(data)
|
|
@@ -81,10 +85,20 @@ def main():
|
|
| 81 |
display_materiality_matrix(selected_company, data, bziiit_data)
|
| 82 |
|
| 83 |
elif ia_mode == "Audit flash RSE de vos contenus":
|
| 84 |
-
rag_pdf_web()
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
elif ia_mode == "Prompt RSE disponibles"
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
elif section_principale == "Documentation":
|
|
|
|
| 17 |
from collaborons import display_company_selection_for_materiality,display_materiality_matrix
|
| 18 |
from documentations import display_documentation
|
| 19 |
from RAG_PDF_WEB import rag_pdf_web
|
| 20 |
+
from prompt import get_prompts_list,prompt_execution,execute_prompt
|
| 21 |
|
| 22 |
def main():
|
| 23 |
st.markdown(":point_left: Cliquez pour vous inspirer", unsafe_allow_html=True)
|
|
|
|
| 25 |
st.sidebar.title("OPEN DATA & IA au service de la RSE")
|
| 26 |
section_principale = st.sidebar.radio(
|
| 27 |
"Choisissez votre section",
|
| 28 |
+
["Data Bordeaux métropole", "Data bziiit","IA RSE","Documentation"],
|
| 29 |
+
index=2
|
| 30 |
)
|
| 31 |
|
| 32 |
if section_principale == "Data Bordeaux métropole":
|
|
|
|
| 71 |
"Matrice de matérialité"
|
| 72 |
]
|
| 73 |
)
|
| 74 |
+
|
| 75 |
if ia_mode == "Parties prenantes":
|
| 76 |
data, bziiit_data = fetch_data()
|
| 77 |
selected_company = display_company_selection_for_materiality(data)
|
| 78 |
if selected_company:
|
| 79 |
display_materiality_partiesprenantes(selected_company, data, bziiit_data)
|
| 80 |
+
|
| 81 |
elif ia_mode == "Matrice de matérialité":
|
| 82 |
data, bziiit_data = fetch_data()
|
| 83 |
selected_company = display_company_selection_for_materiality(data)
|
|
|
|
| 85 |
display_materiality_matrix(selected_company, data, bziiit_data)
|
| 86 |
|
| 87 |
elif ia_mode == "Audit flash RSE de vos contenus":
|
| 88 |
+
vectorstore, chain = rag_pdf_web()
|
| 89 |
+
if vectorstore and chain:
|
| 90 |
+
st.session_state['vectorstore'] = vectorstore
|
| 91 |
+
st.session_state['chain'] = chain
|
| 92 |
|
| 93 |
+
elif ia_mode == "Prompt RSE disponibles":
|
| 94 |
+
get_prompts_list()
|
| 95 |
+
|
| 96 |
+
elif ia_mode == "Générations de contenus RSE":
|
| 97 |
+
st.header("Exécutez un prompt")
|
| 98 |
+
|
| 99 |
+
selected_prompt = prompt_execution()
|
| 100 |
+
if selected_prompt:
|
| 101 |
+
execute_prompt(selected_prompt)
|
| 102 |
|
| 103 |
|
| 104 |
elif section_principale == "Documentation":
|
data_manager_bziiit.py
CHANGED
|
@@ -34,6 +34,22 @@ def get_engaged_brands():
|
|
| 34 |
st.error(f"Échec de récupération des marques engagées: {response.text}")
|
| 35 |
return []
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Fonction consolidant les données labels + projets RSE + marques
|
| 38 |
def get_bziiit_data():
|
| 39 |
labels = get_labels()
|
|
|
|
| 34 |
st.error(f"Échec de récupération des marques engagées: {response.text}")
|
| 35 |
return []
|
| 36 |
|
| 37 |
+
# Fonction de récupération des prompts
|
| 38 |
+
def get_prompts():
|
| 39 |
+
url = f"{BASE_URL}/public/prompts"
|
| 40 |
+
response = requests.get(url)
|
| 41 |
+
if response.status_code == 200:
|
| 42 |
+
return response.json()["response"]
|
| 43 |
+
else:
|
| 44 |
+
st.error(f"Échec de récupération des marques engagées: {response.text}")
|
| 45 |
+
return []
|
| 46 |
+
|
| 47 |
+
def get_prompt_by_id(id):
|
| 48 |
+
prompts = get_prompts()
|
| 49 |
+
for prompt in prompts:
|
| 50 |
+
if prompt.get('id') == id:
|
| 51 |
+
return prompt
|
| 52 |
+
|
| 53 |
# Fonction consolidant les données labels + projets RSE + marques
|
| 54 |
def get_bziiit_data():
|
| 55 |
labels = get_labels()
|
prompt.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from data_manager_bziiit import get_prompts
|
| 4 |
+
from session import get_rag
|
| 5 |
+
|
| 6 |
+
prompts = []
|
| 7 |
+
def get_prompts_list():
|
| 8 |
+
st.header("Prompts")
|
| 9 |
+
prompts = get_prompts()
|
| 10 |
+
|
| 11 |
+
# Check if prompts is a list of dictionaries
|
| 12 |
+
if isinstance(prompts, list) and all(isinstance(i, dict) for i in prompts):
|
| 13 |
+
# Create a DataFrame
|
| 14 |
+
df = pd.DataFrame(prompts)
|
| 15 |
+
|
| 16 |
+
# Check if 'name', 'context', and 'text' are in df columns
|
| 17 |
+
if 'name' in df.columns and 'context' in df.columns and 'text' in df.columns:
|
| 18 |
+
# Extract 'name' from 'context' dictionary
|
| 19 |
+
df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x)
|
| 20 |
+
|
| 21 |
+
# Get first 50 characters from 'text' and add "..." at the end
|
| 22 |
+
df['text'] = df['text'].apply(lambda x: x[:50] + "..." if isinstance(x, str) else x)
|
| 23 |
+
|
| 24 |
+
# Group by 'context'
|
| 25 |
+
grouped = df.groupby('context')
|
| 26 |
+
|
| 27 |
+
for name, group in grouped:
|
| 28 |
+
st.subheader(name) # Display the context name as a subheader
|
| 29 |
+
for i, row in group.iterrows():
|
| 30 |
+
col1, col2, col3, col4 = st.columns((1, 2, 2, 1))
|
| 31 |
+
col1.write(i) # index
|
| 32 |
+
col2.write(row['name']) # name
|
| 33 |
+
col3.write(row['text']) # text
|
| 34 |
+
button_phold = col4.empty() # create a placeholder
|
| 35 |
+
do_action = button_phold.button('Show More', key=i)
|
| 36 |
+
if do_action:
|
| 37 |
+
st.text(prompts[i]['text']) # Display the full text
|
| 38 |
+
button_phold.empty() # remove button
|
| 39 |
+
else:
|
| 40 |
+
st.write("Data does not contain 'name', 'context', and 'text' fields.")
|
| 41 |
+
else:
|
| 42 |
+
st.write("Data is not in the expected format (list of dictionaries).")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def prompt_execution():
|
| 46 |
+
prompts = get_prompts()
|
| 47 |
+
|
| 48 |
+
selected_prompt = st.selectbox("Choisissez un prompt", prompts, format_func=lambda prompt: prompt['name'])
|
| 49 |
+
if selected_prompt:
|
| 50 |
+
return selected_prompt
|
| 51 |
+
|
| 52 |
+
return None
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def execute_prompt(prompt):
|
| 56 |
+
vectorstore, chain = get_rag()
|
| 57 |
+
|
| 58 |
+
st.header(prompt['name'])
|
| 59 |
+
st.text(prompt['text'])
|
| 60 |
+
|
| 61 |
+
if vectorstore and chain:
|
| 62 |
+
st.success("Vectorestore et chain trouvés")
|
| 63 |
+
|
| 64 |
+
if st.button("Exécuter le prompt"):
|
| 65 |
+
with st.spinner("Processing..."):
|
| 66 |
+
ambition = chain.invoke(prompt['text'])
|
| 67 |
+
st.markdown("### Réponse :")
|
| 68 |
+
st.markdown(ambition.content)
|
session.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
def get_rag():
|
| 4 |
+
if 'vectorstore' in st.session_state and 'chain' in st.session_state:
|
| 5 |
+
vectorstore = st.session_state['vectorstore']
|
| 6 |
+
chain = st.session_state['chain']
|
| 7 |
+
|
| 8 |
+
return vectorstore, chain
|
| 9 |
+
else:
|
| 10 |
+
return None, None
|