Ilyas KHIAT
commited on
Commit
·
439e01f
1
Parent(s):
81f75af
pdf export
Browse files- app.py +1 -0
- chat_with_pps.py +20 -3
- export_doc.py +67 -0
- high_chart.py +2 -5
- packages.txt +1 -0
- partie_prenante_carte.py +1 -0
- prompt.py +0 -1
- requirements.txt +5 -1
app.py
CHANGED
@@ -26,6 +26,7 @@ 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 |
st.sidebar.title("OPEN DATA & IA au service de la RSE")
|
31 |
section_principale = st.sidebar.radio(
|
|
|
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(
|
chat_with_pps.py
CHANGED
@@ -8,6 +8,8 @@ from langchain_mistralai.chat_models import ChatMistralAI
|
|
8 |
from download_chart import construct_plot
|
9 |
from prompt import get_prompts_list
|
10 |
from st_copy_to_clipboard import st_copy_to_clipboard
|
|
|
|
|
11 |
|
12 |
|
13 |
load_dotenv()
|
@@ -85,11 +87,19 @@ def choose_model(index):
|
|
85 |
if st.button("Valider"):
|
86 |
st.rerun()
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
def display_chat():
|
89 |
# app config
|
90 |
st.title("Chatbot")
|
91 |
-
|
92 |
-
|
93 |
models_name = {
|
94 |
"Mistral (FR)":1,
|
95 |
"GPT-4o":0
|
@@ -106,15 +116,20 @@ def display_chat():
|
|
106 |
|
107 |
#sticky bar at the top
|
108 |
header = st.container()
|
109 |
-
col1,col2,col3 = header.columns([
|
110 |
|
111 |
if col1.button("Prompts"):
|
112 |
show_prompts()
|
113 |
if col2.button(f"Modèle: {st.session_state.model}"):
|
114 |
index = models_name[st.session_state.model]
|
115 |
choose_model(index)
|
|
|
|
|
|
|
|
|
116 |
header.write("""<div class='fixed-header'/>""", unsafe_allow_html=True)
|
117 |
|
|
|
118 |
# Custom CSS for the sticky header
|
119 |
st.markdown(
|
120 |
"""
|
@@ -171,5 +186,7 @@ def display_chat():
|
|
171 |
st_copy_to_clipboard(response)
|
172 |
if "cartographie" in response:
|
173 |
display_chart()
|
|
|
|
|
174 |
|
175 |
st.session_state.chat_history.append(AIMessage(content=response))
|
|
|
8 |
from download_chart import construct_plot
|
9 |
from prompt import get_prompts_list
|
10 |
from st_copy_to_clipboard import st_copy_to_clipboard
|
11 |
+
from high_chart import test_chart
|
12 |
+
from export_doc import export_conversation
|
13 |
|
14 |
|
15 |
load_dotenv()
|
|
|
87 |
if st.button("Valider"):
|
88 |
st.rerun()
|
89 |
|
90 |
+
@st.experimental_dialog("Ma cartographie",width="large")
|
91 |
+
def disp_carto_in_chat():
|
92 |
+
test_chart()
|
93 |
+
|
94 |
+
@st.experimental_dialog("Telecharger",width="large")
|
95 |
+
def dowmload_history():
|
96 |
+
summary = get_response("Donne moi un RESUME de la Conversation", st.session_state.chat_history,format_context(st.session_state['pp_grouped'],st.session_state['Nom de la marque']),st.session_state.model)
|
97 |
+
summary = ''.join(summary)
|
98 |
+
export_conversation(AIMessage(content=summary).content)
|
99 |
+
|
100 |
def display_chat():
|
101 |
# app config
|
102 |
st.title("Chatbot")
|
|
|
|
|
103 |
models_name = {
|
104 |
"Mistral (FR)":1,
|
105 |
"GPT-4o":0
|
|
|
116 |
|
117 |
#sticky bar at the top
|
118 |
header = st.container()
|
119 |
+
col1,col2,col3, col4 = header.columns([2,3,2,4])
|
120 |
|
121 |
if col1.button("Prompts"):
|
122 |
show_prompts()
|
123 |
if col2.button(f"Modèle: {st.session_state.model}"):
|
124 |
index = models_name[st.session_state.model]
|
125 |
choose_model(index)
|
126 |
+
if col3.button("Ma Carto"):
|
127 |
+
disp_carto_in_chat()
|
128 |
+
if col4.button("Télécharger"):
|
129 |
+
dowmload_history()
|
130 |
header.write("""<div class='fixed-header'/>""", unsafe_allow_html=True)
|
131 |
|
132 |
+
|
133 |
# Custom CSS for the sticky header
|
134 |
st.markdown(
|
135 |
"""
|
|
|
186 |
st_copy_to_clipboard(response)
|
187 |
if "cartographie" in response:
|
188 |
display_chart()
|
189 |
+
if "rajoute" in response:
|
190 |
+
st.session_state['pp_grouped'].append({"name":"partie prenante","x":0,"y":0})
|
191 |
|
192 |
st.session_state.chat_history.append(AIMessage(content=response))
|
export_doc.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import markdown2
|
3 |
+
import pdfkit
|
4 |
+
from io import BytesIO
|
5 |
+
from IPython.display import display, FileLink
|
6 |
+
import base64
|
7 |
+
from langchain_core.messages import AIMessage, HumanMessage
|
8 |
+
|
9 |
+
|
10 |
+
def create_pdf_from_markdown(logo_path, image_path, conversation,summary):
|
11 |
+
# Convertir la conversation en markdown
|
12 |
+
markdown_text = "\n".join([f"### {entry['speaker']}:\n {entry['text']}\n ---" for entry in conversation])
|
13 |
+
|
14 |
+
markdown_summary = f"{summary}\n --- \n ---"
|
15 |
+
st.write(markdown_summary)
|
16 |
+
# Convertir le markdown en HTML
|
17 |
+
html_content = markdown2.markdown(markdown_text)
|
18 |
+
html_summary = markdown2.markdown(markdown_summary)
|
19 |
+
|
20 |
+
# image_base64 = base64.b64encode(image_path).decode('utf-8')
|
21 |
+
# Créer le HTML complet avec les images et le texte
|
22 |
+
html_template = f"""
|
23 |
+
<!DOCTYPE html>
|
24 |
+
<html lang="en">
|
25 |
+
<head>
|
26 |
+
<meta charset="UTF-8">
|
27 |
+
</head>
|
28 |
+
<body>
|
29 |
+
<div style="text-align: center;">
|
30 |
+
<h1>Rapport de Conversation {st.session_state["Nom de la marque"]}</h1>
|
31 |
+
<img src="{logo_path}" alt="Logo" style="width: 150px;"/>
|
32 |
+
</div>
|
33 |
+
<div style="text-align: center; margin-top: 20px;">
|
34 |
+
<img src="data:image/png;base64" alt="Cartographie" style="width: 100%;"/>
|
35 |
+
</div>
|
36 |
+
<h2>RESUME</h2>
|
37 |
+
{html_summary}
|
38 |
+
<h2>Historique de la Conversation</h2>
|
39 |
+
{html_content}
|
40 |
+
|
41 |
+
</body>
|
42 |
+
</html>
|
43 |
+
"""
|
44 |
+
|
45 |
+
# Convertir le HTML en PDF
|
46 |
+
pdf = pdfkit.from_string(html_template, False)
|
47 |
+
return pdf
|
48 |
+
|
49 |
+
def get_conversation():
|
50 |
+
conversation = []
|
51 |
+
for message in st.session_state.chat_history:
|
52 |
+
if isinstance(message, AIMessage):
|
53 |
+
conversation.append({"speaker": "AI", "text": message.content})
|
54 |
+
elif isinstance(message, HumanMessage):
|
55 |
+
conversation.append({"speaker": "Moi", "text": message.content})
|
56 |
+
return conversation
|
57 |
+
|
58 |
+
|
59 |
+
def export_conversation(summary):
|
60 |
+
logo_path = "https://static.wixstatic.com/media/d7d3da_b69e03ae99224f7d8b6e358918e60071~mv2.png/v1/crop/x_173,y_0,w_1906,h_938/fill/w_242,h_119,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/BZIIIT_LOGO-HORIZ-COULEUR.png" # Replace with your image path
|
61 |
+
conversation = get_conversation()
|
62 |
+
image_path = "newplot.png"
|
63 |
+
pdf = create_pdf_from_markdown(logo_path, image_path, conversation,summary)
|
64 |
+
st.success("PDF généré avec succès!")
|
65 |
+
if st.download_button("Télécharger le PDF", data=pdf, file_name=f"Cartographie {st.session_state["Nom de la marque"]}.pdf", mime="application/pdf"):
|
66 |
+
st.rerun()
|
67 |
+
|
high_chart.py
CHANGED
@@ -183,22 +183,19 @@ def construct_data():
|
|
183 |
|
184 |
def test_chart():
|
185 |
#The component can render any highchart definition
|
186 |
-
if len(st.session_state['pp_grouped']) == 0:
|
187 |
return None
|
|
|
188 |
points = st.session_state['pp_grouped']
|
189 |
cd2["series"][0]["data"] = points
|
190 |
chart = hct.streamlit_highcharts(cd2,640) #640 is the chart height
|
191 |
# if chart:
|
192 |
# st.session_state['pp_grouped'] = chart
|
193 |
-
emp = st.empty()
|
194 |
-
|
195 |
-
|
196 |
|
197 |
col0, col1, col2, col3 = st.columns([1,1,1,1])
|
198 |
|
199 |
if col1.button("Sauvegarder",key="save"):
|
200 |
st.session_state['pp_grouped'] = chart.copy()
|
201 |
-
emp.success("Saved")
|
202 |
st.experimental_rerun()
|
203 |
|
204 |
if col2.button("Télécharger",key="download"):
|
|
|
183 |
|
184 |
def test_chart():
|
185 |
#The component can render any highchart definition
|
186 |
+
if "pp_grouped" not in st.session_state or len(st.session_state['pp_grouped']) == 0:
|
187 |
return None
|
188 |
+
|
189 |
points = st.session_state['pp_grouped']
|
190 |
cd2["series"][0]["data"] = points
|
191 |
chart = hct.streamlit_highcharts(cd2,640) #640 is the chart height
|
192 |
# if chart:
|
193 |
# st.session_state['pp_grouped'] = chart
|
|
|
|
|
|
|
194 |
|
195 |
col0, col1, col2, col3 = st.columns([1,1,1,1])
|
196 |
|
197 |
if col1.button("Sauvegarder",key="save"):
|
198 |
st.session_state['pp_grouped'] = chart.copy()
|
|
|
199 |
st.experimental_rerun()
|
200 |
|
201 |
if col2.button("Télécharger",key="download"):
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
wkhtmltopdf
|
partie_prenante_carte.py
CHANGED
@@ -290,6 +290,7 @@ def display_pp():
|
|
290 |
|
291 |
load_dotenv()
|
292 |
fire_crawl_api_key = os.getenv("FIRECRAWL_API_KEY")
|
|
|
293 |
#check if brand name and description are already set
|
294 |
if "Nom de la marque" not in st.session_state:
|
295 |
st.session_state["Nom de la marque"] = ""
|
|
|
290 |
|
291 |
load_dotenv()
|
292 |
fire_crawl_api_key = os.getenv("FIRECRAWL_API_KEY")
|
293 |
+
|
294 |
#check if brand name and description are already set
|
295 |
if "Nom de la marque" not in st.session_state:
|
296 |
st.session_state["Nom de la marque"] = ""
|
prompt.py
CHANGED
@@ -4,7 +4,6 @@ import pandas as pd
|
|
4 |
from data_manager_bziiit import get_prompts
|
5 |
from langchain_core.messages import AIMessage, HumanMessage
|
6 |
from session import get_rag
|
7 |
-
import pyperclip
|
8 |
|
9 |
prompts = []
|
10 |
def get_prompts_list():
|
|
|
4 |
from data_manager_bziiit import get_prompts
|
5 |
from langchain_core.messages import AIMessage, HumanMessage
|
6 |
from session import get_rag
|
|
|
7 |
|
8 |
prompts = []
|
9 |
def get_prompts_list():
|
requirements.txt
CHANGED
@@ -38,4 +38,8 @@ langchain-core
|
|
38 |
langchain-mistralai
|
39 |
firecrawl-py
|
40 |
st_copy_to_clipboard
|
41 |
-
pyperclip
|
|
|
|
|
|
|
|
|
|
38 |
langchain-mistralai
|
39 |
firecrawl-py
|
40 |
st_copy_to_clipboard
|
41 |
+
pyperclip
|
42 |
+
fpdf2
|
43 |
+
markdown2
|
44 |
+
base64
|
45 |
+
io
|