Ilyas KHIAT
commited on
Commit
·
b7289c6
1
Parent(s):
fded6e8
cartographie
Browse files- .streamlit/.env +1 -0
- app.py +15 -4
- partie_prenante_carte.py +187 -0
- partiesprenantes.py +1 -0
- pp_viz.py +41 -0
- requirements.txt +5 -1
- session.py +10 -1
.streamlit/.env
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
API_TOKEN_PERPLEXITYAI = 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
|
|
|
|
|
|
| 1 |
API_TOKEN_PERPLEXITYAI = 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
|
| 2 |
+
OPENAI_API_KEY = sk-proj-2bop2HKuCcRui0omQJnYT3BlbkFJQChzXj1sc6N3FfwV6fk2
|
app.py
CHANGED
|
@@ -8,6 +8,8 @@ from statistiques import main as display_statistics
|
|
| 8 |
from ActionsRSE import display_actions_rse
|
| 9 |
from AnalyseActionsRSE import display_analyse_actions_rse
|
| 10 |
from partiesprenantes import display_materiality_partiesprenantes
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Import modifiédes fonctions liées aux scripts
|
| 13 |
from projetRSE import display_rse_projects
|
|
@@ -68,15 +70,24 @@ def main():
|
|
| 68 |
"Prompt RSE disponibles",
|
| 69 |
"Générations de contenus RSE",
|
| 70 |
"Parties prenantes",
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
elif ia_mode == "Matrice de matérialité":
|
| 82 |
data, bziiit_data = fetch_data()
|
|
|
|
| 8 |
from ActionsRSE import display_actions_rse
|
| 9 |
from AnalyseActionsRSE import display_analyse_actions_rse
|
| 10 |
from partiesprenantes import display_materiality_partiesprenantes
|
| 11 |
+
from partie_prenante_carte import display_pp
|
| 12 |
+
from pp_viz import display_viz
|
| 13 |
|
| 14 |
# Import modifiédes fonctions liées aux scripts
|
| 15 |
from projetRSE import display_rse_projects
|
|
|
|
| 70 |
"Prompt RSE disponibles",
|
| 71 |
"Générations de contenus RSE",
|
| 72 |
"Parties prenantes",
|
| 73 |
+
"Cartographie",
|
| 74 |
"Matrice de matérialité"
|
| 75 |
]
|
| 76 |
)
|
| 77 |
|
| 78 |
if ia_mode == "Parties prenantes":
|
| 79 |
+
# data, bziiit_data = fetch_data()
|
| 80 |
+
# selected_company = display_company_selection_for_materiality(data)
|
| 81 |
+
# if selected_company:
|
| 82 |
+
# display_materiality_partiesprenantes(selected_company, data, bziiit_data)
|
| 83 |
+
display_pp()
|
| 84 |
+
|
| 85 |
+
elif ia_mode == "Cartographie":
|
| 86 |
+
# data, bziiit_data = fetch_data()
|
| 87 |
+
# selected_company = display_company_selection_for_materiality(data)
|
| 88 |
+
# if selected_company:
|
| 89 |
+
# display_materiality_partiesprenantes(selected_company, data, bziiit_data)
|
| 90 |
+
display_viz()
|
| 91 |
|
| 92 |
elif ia_mode == "Matrice de matérialité":
|
| 93 |
data, bziiit_data = fetch_data()
|
partie_prenante_carte.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
import streamlit as st
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from PyPDF2 import PdfReader
|
| 9 |
+
from langchain.text_splitter import CharacterTextSplitter,RecursiveCharacterTextSplitter
|
| 10 |
+
from langchain_experimental.text_splitter import SemanticChunker
|
| 11 |
+
from langchain_community.embeddings import OpenAIEmbeddings
|
| 12 |
+
from langchain_community.vectorstores import FAISS
|
| 13 |
+
from langchain_community.chat_models import ChatOpenAI
|
| 14 |
+
from langchain.llms import HuggingFaceHub
|
| 15 |
+
from langchain import hub
|
| 16 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 17 |
+
from langchain_core.runnables import RunnablePassthrough
|
| 18 |
+
from langchain_community.document_loaders import WebBaseLoader
|
| 19 |
+
from langchain_core.prompts.prompt import PromptTemplate
|
| 20 |
+
import altair as alt
|
| 21 |
+
from session import set_partie_prenante
|
| 22 |
+
import os
|
| 23 |
+
from streamlit_vertical_slider import vertical_slider
|
| 24 |
+
|
| 25 |
+
load_dotenv()
|
| 26 |
+
|
| 27 |
+
def get_docs_from_website(urls):
|
| 28 |
+
loader = WebBaseLoader(urls, header_template={
|
| 29 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
|
| 30 |
+
})
|
| 31 |
+
docs = loader.load()
|
| 32 |
+
return docs
|
| 33 |
+
|
| 34 |
+
def get_doc_chunks(docs):
|
| 35 |
+
# Split the loaded data
|
| 36 |
+
# text_splitter = RecursiveCharacterTextSplitter(
|
| 37 |
+
# chunk_size=500,
|
| 38 |
+
# chunk_overlap=100)
|
| 39 |
+
|
| 40 |
+
text_splitter = SemanticChunker(OpenAIEmbeddings())
|
| 41 |
+
|
| 42 |
+
docs = text_splitter.split_documents(docs)
|
| 43 |
+
return docs
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def disp_test():
|
| 47 |
+
chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
|
| 48 |
+
st.scatter_chart(chart_data)
|
| 49 |
+
|
| 50 |
+
def get_vectorstore_from_docs(doc_chunks):
|
| 51 |
+
embedding = OpenAIEmbeddings(model="text-embedding-3-large")
|
| 52 |
+
vectorstore = FAISS.from_documents(documents=doc_chunks, embedding=embedding)
|
| 53 |
+
return vectorstore
|
| 54 |
+
|
| 55 |
+
def get_conversation_chain(vectorstore):
|
| 56 |
+
llm = ChatOpenAI(model="gpt-4o",temperature=0.5, max_tokens=2048)
|
| 57 |
+
retriever=vectorstore.as_retriever()
|
| 58 |
+
|
| 59 |
+
prompt = hub.pull("rlm/rag-prompt")
|
| 60 |
+
# Chain
|
| 61 |
+
rag_chain = (
|
| 62 |
+
{"context": retriever , "question": RunnablePassthrough()}
|
| 63 |
+
| prompt
|
| 64 |
+
| llm
|
| 65 |
+
)
|
| 66 |
+
return rag_chain
|
| 67 |
+
|
| 68 |
+
# FILL THE PROMPT FOR THE QUESTION VARIABLE THAT WILL BE USED IN THE RAG PROMPT, ATTENTION NOT CONFUSE WITH THE RAG PROMPT
|
| 69 |
+
def fill_promptQ_template(input_variables, template):
|
| 70 |
+
prompt = PromptTemplate(input_variables=["BRAND_NAME","BRAND_DESCRIPTION"], template=template)
|
| 71 |
+
return prompt.format(BRAND_NAME=input_variables["BRAND_NAME"], BRAND_DESCRIPTION=input_variables["BRAND_DESCRIPTION"])
|
| 72 |
+
|
| 73 |
+
template_extraction_PP = '''
|
| 74 |
+
Objectif : identifiez et proposez tout les noms de marques qui serviront comme partie prenante de la marque suivante pour développer un marketing de coopération (co-op marketing)
|
| 75 |
+
|
| 76 |
+
Le nom de la marque de référence est le suivant : {BRAND_NAME}
|
| 77 |
+
Son activité est la suivante : {BRAND_DESCRIPTION}
|
| 78 |
+
|
| 79 |
+
TA REPONSE DOIT ETRE SOUS FORME DE LISTE DE NOMS DE MARQUES
|
| 80 |
+
'''
|
| 81 |
+
#don't forget to add the input variables from the maim function
|
| 82 |
+
|
| 83 |
+
def text_to_list(text):
|
| 84 |
+
lines = text.replace("- ","").split('\n')
|
| 85 |
+
|
| 86 |
+
lines = [line.split() for line in lines]
|
| 87 |
+
items = [[' '.join(line[:-1]),line[-1]] for line in lines]
|
| 88 |
+
# Assuming `items` is the list of items
|
| 89 |
+
for item in items:
|
| 90 |
+
item[1] = re.sub(r'\D', '', item[1])
|
| 91 |
+
return items
|
| 92 |
+
|
| 93 |
+
def extract_pp(urls,input_variables):
|
| 94 |
+
template_extraction_PP = '''
|
| 95 |
+
Objectif : identifiez et proposez tout les noms de marques qui serviront comme partie prenante de la marque suivante pour développer un marketing de coopération (co-op marketing)
|
| 96 |
+
|
| 97 |
+
Le nom de la marque de référence est le suivant : {BRAND_NAME}
|
| 98 |
+
Son activité est la suivante : {BRAND_DESCRIPTION}
|
| 99 |
+
|
| 100 |
+
TA REPONSE DOIT ETRE SOUS FORME DE LISTE DE NOMS DE MARQUES
|
| 101 |
+
'''
|
| 102 |
+
#don't forget to add the input variables from the maim function
|
| 103 |
+
|
| 104 |
+
docs = get_docs_from_website(urls)
|
| 105 |
+
|
| 106 |
+
#get text chunks
|
| 107 |
+
text_chunks = get_doc_chunks(docs)
|
| 108 |
+
|
| 109 |
+
#create vectorstore
|
| 110 |
+
vectorstore = get_vectorstore_from_docs(text_chunks)
|
| 111 |
+
|
| 112 |
+
chain = get_conversation_chain(vectorstore)
|
| 113 |
+
|
| 114 |
+
question = fill_promptQ_template(input_variables, template_extraction_PP)
|
| 115 |
+
|
| 116 |
+
response = chain.invoke(question)
|
| 117 |
+
|
| 118 |
+
# version plus poussée a considérer
|
| 119 |
+
# each item in the list is a list with the name of the brand and the similarity percentage
|
| 120 |
+
#partie_prenante = text_to_list(response.content)
|
| 121 |
+
|
| 122 |
+
#version simple
|
| 123 |
+
partie_prenante = response.content.replace("- ","").split('\n')
|
| 124 |
+
|
| 125 |
+
return partie_prenante
|
| 126 |
+
|
| 127 |
+
def disp_vertical_slider(partie_prenante):
|
| 128 |
+
number_of_sliders = len(partie_prenante)
|
| 129 |
+
st.set_page_config(layout="wide")
|
| 130 |
+
st.subheader("Vertical Slider")
|
| 131 |
+
st.title("Vertical Slider")
|
| 132 |
+
st.write("This is a vertical slider example")
|
| 133 |
+
bar = st.columns(number_of_sliders)
|
| 134 |
+
for i in range(number_of_sliders):
|
| 135 |
+
with bar[i]:
|
| 136 |
+
tst = vertical_slider(
|
| 137 |
+
label=partie_prenante[i],
|
| 138 |
+
height=100,
|
| 139 |
+
key=partie_prenante[i],
|
| 140 |
+
default_value=50,
|
| 141 |
+
thumb_color= "orange", #Optional - Defaults to Streamlit Red
|
| 142 |
+
step=1,
|
| 143 |
+
min_value=0,
|
| 144 |
+
max_value=100,
|
| 145 |
+
value_always_visible=False,
|
| 146 |
+
)
|
| 147 |
+
st.write(tst)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def display_pp():
|
| 151 |
+
load_dotenv()
|
| 152 |
+
st.header("INDIQUEZ VOS PAGES WEB ET/OU DOCUMENTS D’ENTREPRISE POUR AUDITER LE CONTENU RSE")
|
| 153 |
+
loaded = False
|
| 154 |
+
option = st.radio("Source", ("A partir de votre site web", "A partir de vos documents entreprise"))
|
| 155 |
+
|
| 156 |
+
if option == "A partir de votre site web":
|
| 157 |
+
url1 = st.text_input("URL 1")
|
| 158 |
+
brand_name = st.text_input("Nom de la marque")
|
| 159 |
+
brand_description = st.text_area("Description de la marque")
|
| 160 |
+
if st.button("Process") and loaded == False:
|
| 161 |
+
loaded = True
|
| 162 |
+
with st.spinner("Processing..."):
|
| 163 |
+
input_variables = {"BRAND_NAME": brand_name, "BRAND_DESCRIPTION": brand_description}
|
| 164 |
+
partie_prenante = extract_pp([url1], input_variables)
|
| 165 |
+
partie_prenante = sorted(partie_prenante)
|
| 166 |
+
set_partie_prenante(partie_prenante)
|
| 167 |
+
st.write(pd.DataFrame(partie_prenante, columns=["Partie prenante"]))
|
| 168 |
+
|
| 169 |
+
# alphabet = [ pp[0] for pp in partie_prenante]
|
| 170 |
+
# pouvoir = [ 50 for _ in range(len(partie_prenante))]
|
| 171 |
+
# df = pd.DataFrame({'partie_prenante': partie_prenante, 'pouvoir': pouvoir, 'code couleur': partie_prenante})
|
| 172 |
+
# st.write(df)
|
| 173 |
+
|
| 174 |
+
# c = (
|
| 175 |
+
# alt.Chart(df)
|
| 176 |
+
# .mark_circle(size=300)
|
| 177 |
+
# .encode(x="partie_prenante", y=alt.Y("pouvoir",scale=alt.Scale(domain=[0,100])), color="code couleur")
|
| 178 |
+
# )
|
| 179 |
+
# st.subheader("Vertical Slider")
|
| 180 |
+
# age = st.slider("How old are you?", 0, 130, 25)
|
| 181 |
+
# st.write("I'm ", age, "years old")
|
| 182 |
+
|
| 183 |
+
# disp_vertical_slider(partie_prenante)
|
| 184 |
+
# st.altair_chart(c, use_container_width=True)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
partiesprenantes.py
CHANGED
|
@@ -30,6 +30,7 @@ def display_company_selection_for_materiality(data):
|
|
| 30 |
|
| 31 |
selected_company = st.selectbox('Sélectionnez une entreprise', companies, index=0)
|
| 32 |
|
|
|
|
| 33 |
# If the default selection is still selected, return None
|
| 34 |
if selected_company == "Sélectionner l'entreprise engagée à découvrir":
|
| 35 |
return None
|
|
|
|
| 30 |
|
| 31 |
selected_company = st.selectbox('Sélectionnez une entreprise', companies, index=0)
|
| 32 |
|
| 33 |
+
|
| 34 |
# If the default selection is still selected, return None
|
| 35 |
if selected_company == "Sélectionner l'entreprise engagée à découvrir":
|
| 36 |
return None
|
pp_viz.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
import altair as alt
|
| 7 |
+
from session import get_partie_prenante
|
| 8 |
+
import os
|
| 9 |
+
from streamlit_vertical_slider import vertical_slider
|
| 10 |
+
|
| 11 |
+
def display_viz():
|
| 12 |
+
st.header("Viz")
|
| 13 |
+
st.title("Visualisation des parties prenantes")
|
| 14 |
+
partie_prenante = get_partie_prenante()
|
| 15 |
+
alphabet = [ pp[0] for pp in partie_prenante]
|
| 16 |
+
pouvoir = [ 50 for _ in range(len(partie_prenante))]
|
| 17 |
+
df = pd.DataFrame({'partie_prenante': partie_prenante, 'pouvoir': pouvoir, 'code couleur': partie_prenante})
|
| 18 |
+
st.write(df)
|
| 19 |
+
c = (
|
| 20 |
+
alt.Chart(df)
|
| 21 |
+
.mark_circle(size=300)
|
| 22 |
+
.encode(x="partie_prenante", y=alt.Y("pouvoir",scale=alt.Scale(domain=[0,100])), color="code couleur")
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
number_of_sliders = len(partie_prenante)
|
| 26 |
+
st.write("Modifiez le pouvoir des parties prenantes en utilisant les sliders ci-dessous")
|
| 27 |
+
bar = st.columns(number_of_sliders)
|
| 28 |
+
for i in range(number_of_sliders):
|
| 29 |
+
with bar[i]:
|
| 30 |
+
df["pouvoir"][i] = vertical_slider(
|
| 31 |
+
label=partie_prenante[i],
|
| 32 |
+
height=100,
|
| 33 |
+
key=partie_prenante[i],
|
| 34 |
+
default_value=50,
|
| 35 |
+
thumb_color= "orange", #Optional - Defaults to Streamlit Red
|
| 36 |
+
step=1,
|
| 37 |
+
min_value=0,
|
| 38 |
+
max_value=100,
|
| 39 |
+
value_always_visible=False,
|
| 40 |
+
)
|
| 41 |
+
st.altair_chart(c, use_container_width=True)
|
requirements.txt
CHANGED
|
@@ -23,4 +23,8 @@ openai
|
|
| 23 |
InstructorEmbedding
|
| 24 |
sentence-transformers==2.2.2
|
| 25 |
langchainhub
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
InstructorEmbedding
|
| 24 |
sentence-transformers==2.2.2
|
| 25 |
langchainhub
|
| 26 |
+
plotly==5.22.0
|
| 27 |
+
pandas
|
| 28 |
+
"altair[all]"
|
| 29 |
+
streamlit-vertical-slider
|
| 30 |
+
streamlit_toggle
|
session.py
CHANGED
|
@@ -11,4 +11,13 @@ def get_rag():
|
|
| 11 |
|
| 12 |
def set_rag(vectorstore, chain):
|
| 13 |
st.session_state['vectorstore'] = vectorstore
|
| 14 |
-
st.session_state['chain'] = chain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def set_rag(vectorstore, chain):
|
| 13 |
st.session_state['vectorstore'] = vectorstore
|
| 14 |
+
st.session_state['chain'] = chain
|
| 15 |
+
|
| 16 |
+
def set_partie_prenante(partie_prenante):
|
| 17 |
+
st.session_state['partie_prenante'] = partie_prenante
|
| 18 |
+
|
| 19 |
+
def get_partie_prenante():
|
| 20 |
+
if 'partie_prenante' in st.session_state:
|
| 21 |
+
return st.session_state['partie_prenante']
|
| 22 |
+
else:
|
| 23 |
+
return None
|