Spaces:
Sleeping
Sleeping
Ilyas KHIAT
commited on
Commit
•
796a4bb
1
Parent(s):
74fce9f
upgrades multi url
Browse files- partie_prenante_carte.py +79 -31
- pp_viz.py +15 -9
- requirements.txt +2 -0
- session.py +9 -1
partie_prenante_carte.py
CHANGED
@@ -21,6 +21,7 @@ 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 |
|
@@ -90,6 +91,25 @@ def text_to_list(text):
|
|
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)
|
@@ -147,41 +167,69 @@ def disp_vertical_slider(partie_prenante):
|
|
147 |
st.write(tst)
|
148 |
|
149 |
|
|
|
150 |
def display_pp():
|
|
|
151 |
load_dotenv()
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
|
187 |
|
|
|
21 |
from session import set_partie_prenante
|
22 |
import os
|
23 |
from streamlit_vertical_slider import vertical_slider
|
24 |
+
from pp_viz import display_viz
|
25 |
|
26 |
load_dotenv()
|
27 |
|
|
|
91 |
item[1] = re.sub(r'\D', '', item[1])
|
92 |
return items
|
93 |
|
94 |
+
def display_list_urls():
|
95 |
+
for index, item in enumerate(st.session_state["urls"]):
|
96 |
+
emp = st.empty() # Create an empty placeholder
|
97 |
+
col1, col2 = emp.columns([7, 3]) # Divide the space into two columns
|
98 |
+
|
99 |
+
# Button to delete the entry, placed in the second column
|
100 |
+
if col2.button("❌", key=f"but{index}"):
|
101 |
+
del st.session_state.urls[index]
|
102 |
+
del st.session_state["parties_prenantes"][index]
|
103 |
+
st.experimental_rerun() # Rerun the app to update the display
|
104 |
+
|
105 |
+
if len(st.session_state.urls) > index:
|
106 |
+
# Instead of using markdown, use an expander in the first column
|
107 |
+
with col1.expander(f"URL {index}: {item}"):
|
108 |
+
pp = st.session_state["parties_prenantes"][index]
|
109 |
+
st.write(pd.DataFrame(pp, columns=["Partie prenante"]))
|
110 |
+
else:
|
111 |
+
emp.empty() # Clear the placeholder if the index exceeds the list
|
112 |
+
|
113 |
def extract_pp(urls,input_variables):
|
114 |
template_extraction_PP = '''
|
115 |
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)
|
|
|
167 |
st.write(tst)
|
168 |
|
169 |
|
170 |
+
|
171 |
def display_pp():
|
172 |
+
|
173 |
load_dotenv()
|
174 |
+
#check if brand name and description are already set
|
175 |
+
if "Nom de la marque" not in st.session_state:
|
176 |
+
st.session_state["Nom de la marque"] = ""
|
177 |
+
if "Description de la marque" not in st.session_state:
|
178 |
+
st.session_state["Description de la marque"] = ""
|
179 |
+
|
180 |
+
#check if urls and partie prenante are already set
|
181 |
+
if "urls" not in st.session_state:
|
182 |
+
st.session_state["urls"] = []
|
183 |
+
if "parties_prenantes" not in st.session_state:
|
184 |
+
st.session_state['parties_prenantes'] = []
|
185 |
+
|
186 |
+
st.header("Parties prenantes de la marque")
|
187 |
+
|
188 |
+
#set brand name and description
|
189 |
+
brand_name = st.text_input("Nom de la marque", st.session_state["Nom de la marque"])
|
190 |
+
st.session_state["Nom de la marque"] = brand_name
|
191 |
+
brand_description = st.text_input("Description de la marque", st.session_state["Description de la marque"])
|
192 |
+
st.session_state["Description de la marque"] = brand_description
|
193 |
+
|
194 |
option = st.radio("Source", ("A partir de votre site web", "A partir de vos documents entreprise"))
|
195 |
+
#if the user chooses to extract from website
|
196 |
if option == "A partir de votre site web":
|
197 |
+
|
198 |
+
|
199 |
+
url = st.text_input("Ajouter une URL")
|
200 |
+
|
201 |
+
#if the user clicks on the button
|
202 |
+
if st.button("ajouter"):
|
203 |
+
if url in st.session_state["urls"]:
|
204 |
+
st.error("URL déjà ajoutée")
|
205 |
+
else:
|
206 |
+
with st.spinner("Processing..."):
|
207 |
+
|
208 |
+
#handle the extraction
|
209 |
+
input_variables = {"BRAND_NAME": brand_name, "BRAND_DESCRIPTION": brand_description}
|
210 |
+
partie_prenante = extract_pp([url], input_variables)
|
211 |
+
partie_prenante = sorted(partie_prenante)
|
212 |
+
st.session_state['parties_prenantes'].append(partie_prenante)
|
213 |
+
st.session_state["urls"].append(url)
|
214 |
+
# alphabet = [ pp[0] for pp in partie_prenante]
|
215 |
+
# pouvoir = [ 50 for _ in range(len(partie_prenante))]
|
216 |
+
# df = pd.DataFrame({'partie_prenante': partie_prenante, 'pouvoir': pouvoir, 'code couleur': partie_prenante})
|
217 |
+
# st.write(df)
|
218 |
+
|
219 |
+
# c = (
|
220 |
+
# alt.Chart(df)
|
221 |
+
# .mark_circle(size=300)
|
222 |
+
# .encode(x="partie_prenante", y=alt.Y("pouvoir",scale=alt.Scale(domain=[0,100])), color="code couleur")
|
223 |
+
# )
|
224 |
+
# st.subheader("Vertical Slider")
|
225 |
+
# age = st.slider("How old are you?", 0, 130, 25)
|
226 |
+
# st.write("I'm ", age, "years old")
|
227 |
+
|
228 |
+
# disp_vertical_slider(partie_prenante)
|
229 |
+
# st.altair_chart(c, use_container_width=True)
|
230 |
+
display_list_urls()
|
231 |
+
display_viz()
|
232 |
+
|
233 |
|
234 |
|
235 |
|
pp_viz.py
CHANGED
@@ -4,21 +4,21 @@ import numpy as np
|
|
4 |
import re
|
5 |
|
6 |
import altair as alt
|
7 |
-
from session import
|
8 |
import os
|
9 |
from streamlit_vertical_slider import vertical_slider
|
|
|
10 |
|
11 |
def display_viz():
|
12 |
|
13 |
-
st.header("")
|
14 |
-
st.title("Visualisation des parties prenantes")
|
15 |
|
16 |
-
|
17 |
|
18 |
-
if
|
19 |
-
st.write("
|
20 |
else:
|
21 |
-
|
|
|
22 |
pouvoir = [ 50 for _ in range(len(partie_prenante))]
|
23 |
df = pd.DataFrame({'partie_prenante': partie_prenante, 'pouvoir': pouvoir, 'code couleur': partie_prenante})
|
24 |
c = (
|
@@ -30,17 +30,23 @@ def display_viz():
|
|
30 |
number_of_sliders = len(partie_prenante)
|
31 |
st.write("Modifiez le pouvoir des parties prenantes en utilisant les sliders ci-dessous")
|
32 |
bar = st.columns(number_of_sliders)
|
|
|
|
|
33 |
for i in range(number_of_sliders):
|
34 |
with bar[i]:
|
|
|
35 |
df["pouvoir"][i] = vertical_slider(
|
36 |
label=partie_prenante[i],
|
37 |
height=100,
|
38 |
key=partie_prenante[i],
|
39 |
-
default_value=
|
40 |
thumb_color= "orange", #Optional - Defaults to Streamlit Red
|
41 |
step=1,
|
42 |
min_value=0,
|
43 |
max_value=100,
|
44 |
value_always_visible=False,
|
45 |
)
|
46 |
-
st.altair_chart(c, use_container_width=True)
|
|
|
|
|
|
|
|
4 |
import re
|
5 |
|
6 |
import altair as alt
|
7 |
+
from session import get_parties_prenantes
|
8 |
import os
|
9 |
from streamlit_vertical_slider import vertical_slider
|
10 |
+
from st_draggable_list import DraggableList
|
11 |
|
12 |
def display_viz():
|
13 |
|
|
|
|
|
14 |
|
15 |
+
parties_prenantes = get_parties_prenantes()
|
16 |
|
17 |
+
if parties_prenantes is None or len(parties_prenantes) == 0:
|
18 |
+
st.write("aucune partie prenante n'a été définie")
|
19 |
else:
|
20 |
+
partie_prenante_non_filtre = [item for sublist in parties_prenantes for item in sublist]
|
21 |
+
partie_prenante = sorted(list(set(partie_prenante_non_filtre)))
|
22 |
pouvoir = [ 50 for _ in range(len(partie_prenante))]
|
23 |
df = pd.DataFrame({'partie_prenante': partie_prenante, 'pouvoir': pouvoir, 'code couleur': partie_prenante})
|
24 |
c = (
|
|
|
30 |
number_of_sliders = len(partie_prenante)
|
31 |
st.write("Modifiez le pouvoir des parties prenantes en utilisant les sliders ci-dessous")
|
32 |
bar = st.columns(number_of_sliders)
|
33 |
+
|
34 |
+
|
35 |
for i in range(number_of_sliders):
|
36 |
with bar[i]:
|
37 |
+
temp = 50
|
38 |
df["pouvoir"][i] = vertical_slider(
|
39 |
label=partie_prenante[i],
|
40 |
height=100,
|
41 |
key=partie_prenante[i],
|
42 |
+
default_value=temp,
|
43 |
thumb_color= "orange", #Optional - Defaults to Streamlit Red
|
44 |
step=1,
|
45 |
min_value=0,
|
46 |
max_value=100,
|
47 |
value_always_visible=False,
|
48 |
)
|
49 |
+
st.altair_chart(c, use_container_width=True)
|
50 |
+
data = [{'id':partie_prenante[i], 'name':partie_prenante[i],'pouvoir':int(df["pouvoir"][i])} for i in range(len(partie_prenante))]
|
51 |
+
slist = DraggableList(data)
|
52 |
+
st.write(slist)
|
requirements.txt
CHANGED
@@ -29,3 +29,5 @@ altair[all]
|
|
29 |
streamlit-vertical-slider
|
30 |
streamlit_toggle
|
31 |
langchain_experimental
|
|
|
|
|
|
29 |
streamlit-vertical-slider
|
30 |
streamlit_toggle
|
31 |
langchain_experimental
|
32 |
+
streamlit_draggable_list
|
33 |
+
|
session.py
CHANGED
@@ -14,10 +14,18 @@ def set_rag(vectorstore, chain):
|
|
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 '
|
21 |
return st.session_state['partie_prenante']
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
else:
|
23 |
return None
|
|
|
14 |
st.session_state['chain'] = chain
|
15 |
|
16 |
def set_partie_prenante(partie_prenante):
|
17 |
+
if "partie_prenante" not in st.session_state:
|
18 |
+
st.session_state['partie_prenante'] = []
|
19 |
st.session_state['partie_prenante'] = partie_prenante
|
20 |
|
21 |
def get_partie_prenante():
|
22 |
+
if 'parties_prenante' in st.session_state:
|
23 |
return st.session_state['partie_prenante']
|
24 |
+
else:
|
25 |
+
return None
|
26 |
+
|
27 |
+
def get_parties_prenantes():
|
28 |
+
if 'parties_prenantes' in st.session_state:
|
29 |
+
return st.session_state['parties_prenantes']
|
30 |
else:
|
31 |
return None
|