Spaces:
Sleeping
Sleeping
Ilyas KHIAT
commited on
Commit
•
17b2024
1
Parent(s):
037a278
conso carbon
Browse files- app.py +29 -0
- chat_with_pps.py +10 -0
- comparateur.py +15 -0
- emissions.csv +0 -0
- feuille.svg +3 -0
- partie_prenante_carte.py +10 -1
app.py
CHANGED
@@ -9,6 +9,7 @@ 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 |
|
13 |
|
14 |
# Import modifiédes fonctions liées aux scripts
|
@@ -23,10 +24,22 @@ from prompt import get_prompts_list,prompt_execution,execute_prompt
|
|
23 |
from chat_with_pps import display_chat
|
24 |
from high_chart import test_chart
|
25 |
from chat_te import display_chat_te
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def main():
|
28 |
st.markdown(":point_left: Cliquez pour vous inspirer", unsafe_allow_html=True)
|
29 |
|
|
|
|
|
|
|
|
|
30 |
|
31 |
st.sidebar.title("OPEN DATA & IA au service de la RSE")
|
32 |
section_principale = st.sidebar.radio(
|
@@ -119,5 +132,21 @@ def main():
|
|
119 |
st.sidebar.markdown("[email protected]")
|
120 |
st.sidebar.markdown("---")
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
if __name__ == "__main__":
|
123 |
main()
|
|
|
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 codecarbon import EmissionsTracker
|
13 |
|
14 |
|
15 |
# Import modifiédes fonctions liées aux scripts
|
|
|
24 |
from chat_with_pps import display_chat
|
25 |
from high_chart import test_chart
|
26 |
from chat_te import display_chat_te
|
27 |
+
from comparateur import *
|
28 |
+
import base64
|
29 |
+
|
30 |
+
# Function to read and encode an SVG file to Base64
|
31 |
+
def load_svg_as_base64(file_path):
|
32 |
+
with open(file_path, "rb") as f:
|
33 |
+
svg_data = f.read()
|
34 |
+
return base64.b64encode(svg_data).decode()
|
35 |
|
36 |
def main():
|
37 |
st.markdown(":point_left: Cliquez pour vous inspirer", unsafe_allow_html=True)
|
38 |
|
39 |
+
if "emission" not in st.session_state:
|
40 |
+
tracker = EmissionsTracker()
|
41 |
+
tracker.start()
|
42 |
+
st.session_state["emission"] = tracker
|
43 |
|
44 |
st.sidebar.title("OPEN DATA & IA au service de la RSE")
|
45 |
section_principale = st.sidebar.radio(
|
|
|
132 |
st.sidebar.markdown("[email protected]")
|
133 |
st.sidebar.markdown("---")
|
134 |
|
135 |
+
svg_file_path = "feuille.svg"
|
136 |
+
svg_base64 = load_svg_as_base64(svg_file_path)
|
137 |
+
st.sidebar.markdown(
|
138 |
+
f"""
|
139 |
+
**Votre consommation Carbone**
|
140 |
+
<img src='data:image/svg+xml;base64,{svg_base64}' alt='svg' width='15' height='15' style='margin-left: 10px;'>
|
141 |
+
""",
|
142 |
+
unsafe_allow_html=True
|
143 |
+
)
|
144 |
+
st.sidebar.markdown(f"<div style='text-align: center;'><b>{st.session_state['emission'].stop()*1000:.3f}</b> g eq. CO2</div>", unsafe_allow_html=True)
|
145 |
+
st.sidebar.write("\n")
|
146 |
+
col1,col2,col3 = st.sidebar.columns([1,1,1])
|
147 |
+
display_comparaison(col1,st.session_state['emission'].stop(),dict_comparaison_1kgCO2["eau en litre"][0]*1000,dict_comparaison_1kgCO2["eau en litre"][1],"ml")
|
148 |
+
display_comparaison(col2,st.session_state['emission'].stop(),dict_comparaison_1kgCO2["smartphones"][0],dict_comparaison_1kgCO2["smartphones"][1],"")
|
149 |
+
display_comparaison(col3,st.session_state['emission'].stop(),dict_comparaison_1kgCO2["voiture en km"][0]*1000,dict_comparaison_1kgCO2["voiture en km"][1],"m")
|
150 |
+
|
151 |
if __name__ == "__main__":
|
152 |
main()
|
chat_with_pps.py
CHANGED
@@ -11,6 +11,9 @@ from high_chart import test_chart
|
|
11 |
from export_doc import export_conversation,convert_pp_to_csv,get_conversation
|
12 |
import random
|
13 |
import pandas as pd
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
load_dotenv()
|
@@ -134,6 +137,7 @@ def disp_carto_in_chat():
|
|
134 |
@st.experimental_dialog("Télécharger",width="small")
|
135 |
def dowmload_history(used_models=None):
|
136 |
brand_name = st.session_state['Nom de la marque']
|
|
|
137 |
format = st.radio("Choisissez le document à télécharger",[f"Rapport des parties prenantes (PDF)",f"Tableau des parties prenantes (CSV)",f"Historique de conversation (Fichier Texte)"],index=None)
|
138 |
if format == f"Rapport des parties prenantes (PDF)":
|
139 |
with st.spinner("Generation en cours..."):
|
@@ -196,6 +200,7 @@ def extract_format_prompts_from_response(response):
|
|
196 |
prompts_container = st.container()
|
197 |
with prompts_container:
|
198 |
for i,prompt in enumerate(prompts):
|
|
|
199 |
temp_p = f"{prompt} ➡️"
|
200 |
st.button(temp_p,key=f"exec_{i}",on_click=lambda i=i: st.session_state.chat_history.append(HumanMessage(content=prompts[i])))
|
201 |
|
@@ -212,6 +217,11 @@ def display_prompts(prompts):
|
|
212 |
|
213 |
|
214 |
def display_chat():
|
|
|
|
|
|
|
|
|
|
|
215 |
# app config
|
216 |
st.title("Chatbot")
|
217 |
models_name = {
|
|
|
11 |
from export_doc import export_conversation,convert_pp_to_csv,get_conversation
|
12 |
import random
|
13 |
import pandas as pd
|
14 |
+
from codecarbon import EmissionsTracker
|
15 |
+
from carbontracker.tracker import CarbonTracker
|
16 |
+
|
17 |
|
18 |
|
19 |
load_dotenv()
|
|
|
137 |
@st.experimental_dialog("Télécharger",width="small")
|
138 |
def dowmload_history(used_models=None):
|
139 |
brand_name = st.session_state['Nom de la marque']
|
140 |
+
st.markdown(f"**l'emission en kgCO2eq jusqu'a maintenant d'apres codecarbon:** \n{st.session_state['emission'].stop()} **kgCO2eq**")
|
141 |
format = st.radio("Choisissez le document à télécharger",[f"Rapport des parties prenantes (PDF)",f"Tableau des parties prenantes (CSV)",f"Historique de conversation (Fichier Texte)"],index=None)
|
142 |
if format == f"Rapport des parties prenantes (PDF)":
|
143 |
with st.spinner("Generation en cours..."):
|
|
|
200 |
prompts_container = st.container()
|
201 |
with prompts_container:
|
202 |
for i,prompt in enumerate(prompts):
|
203 |
+
|
204 |
temp_p = f"{prompt} ➡️"
|
205 |
st.button(temp_p,key=f"exec_{i}",on_click=lambda i=i: st.session_state.chat_history.append(HumanMessage(content=prompts[i])))
|
206 |
|
|
|
217 |
|
218 |
|
219 |
def display_chat():
|
220 |
+
|
221 |
+
if "emission" not in st.session_state:
|
222 |
+
tracker = EmissionsTracker()
|
223 |
+
tracker.start()
|
224 |
+
st.session_state["emission"] = tracker
|
225 |
# app config
|
226 |
st.title("Chatbot")
|
227 |
models_name = {
|
comparateur.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
dict_comparaison_1kgCO2 = {
|
3 |
+
"eau en litre":[374/100,"https://impactco2.fr/icons/eauenbouteille.svg"],
|
4 |
+
"smartphones": [1.16/100,"https://impactco2.fr/icons/smartphone.svg"],
|
5 |
+
"voiture en km": [460/100,"https://impactco2.fr/icons/voiturethermique.svg"],
|
6 |
+
}
|
7 |
+
|
8 |
+
def compare(value_init, ratio_equivalent):
|
9 |
+
return ratio_equivalent * value_init if ratio_equivalent else None
|
10 |
+
|
11 |
+
def display_comparaison(container,value_init, ratio_equivalent,icon, unit):
|
12 |
+
#value_init must be in kgCO2
|
13 |
+
link_url = f"https://impactco2.fr/outils/comparateur?value={value_init}&comparisons=smartphone,eauenbouteille,voiturethermique"
|
14 |
+
container.markdown(f"<div style='text-align: center;'><a href='{link_url}' target='_blank'><img src='{icon}' alt='{unit}' width='50'></div>", unsafe_allow_html=True)
|
15 |
+
container.markdown(f"<div style='text-align: center;'><b>{compare(value_init, ratio_equivalent):.2f}</b> {unit}</div>", unsafe_allow_html=True)
|
emissions.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
feuille.svg
ADDED
partie_prenante_carte.py
CHANGED
@@ -18,6 +18,9 @@ import os
|
|
18 |
from high_chart import test_chart
|
19 |
from chat_with_pps import get_response
|
20 |
|
|
|
|
|
|
|
21 |
load_dotenv()
|
22 |
|
23 |
def get_docs_from_website(urls):
|
@@ -295,7 +298,11 @@ def show_conseil_ia():
|
|
295 |
st.warning("Quittez et saisissez une autre URL")
|
296 |
|
297 |
def display_pp():
|
298 |
-
|
|
|
|
|
|
|
|
|
299 |
load_dotenv()
|
300 |
fire_crawl_api_key = os.getenv("FIRECRAWL_API_KEY")
|
301 |
|
@@ -460,6 +467,8 @@ def display_pp():
|
|
460 |
add_pp_input_text()
|
461 |
display_list_pps()
|
462 |
test_chart()
|
|
|
|
|
463 |
|
464 |
|
465 |
|
|
|
18 |
from high_chart import test_chart
|
19 |
from chat_with_pps import get_response
|
20 |
|
21 |
+
from codecarbon import EmissionsTracker
|
22 |
+
from carbontracker.tracker import CarbonTracker
|
23 |
+
|
24 |
load_dotenv()
|
25 |
|
26 |
def get_docs_from_website(urls):
|
|
|
298 |
st.warning("Quittez et saisissez une autre URL")
|
299 |
|
300 |
def display_pp():
|
301 |
+
if "emission" not in st.session_state:
|
302 |
+
tracker = EmissionsTracker()
|
303 |
+
tracker.start()
|
304 |
+
st.session_state["emission"] = tracker
|
305 |
+
|
306 |
load_dotenv()
|
307 |
fire_crawl_api_key = os.getenv("FIRECRAWL_API_KEY")
|
308 |
|
|
|
467 |
add_pp_input_text()
|
468 |
display_list_pps()
|
469 |
test_chart()
|
470 |
+
emissions:float = st.session_state["emission"].stop()
|
471 |
+
st.write(f"Émissions de CO2: {emissions} kg" )
|
472 |
|
473 |
|
474 |
|