Spaces:
Running
Running
Ilyas KHIAT
commited on
Commit
·
d44debd
1
Parent(s):
53a6b29
enhance
Browse files- audit_page/dialogue_doc.py +26 -19
- requirements.txt +2 -0
audit_page/dialogue_doc.py
CHANGED
@@ -3,9 +3,11 @@ from textwrap import dedent
|
|
3 |
from utils.audit.rag import get_text_from_content_for_doc,get_text_from_content_for_audio
|
4 |
from utils.audit.response_llm import generate_response_via_langchain
|
5 |
from langchain_core.messages import AIMessage, HumanMessage
|
6 |
-
import
|
7 |
from utils.kg.construct_kg import get_graph
|
8 |
from audit_page.knowledge_graph import *
|
|
|
|
|
9 |
|
10 |
def graph_doc_to_json(graph):
|
11 |
nodes = []
|
@@ -132,18 +134,20 @@ def doc_dialog_main():
|
|
132 |
if cr:
|
133 |
col1, col2 = st.columns([2.5, 1.5])
|
134 |
|
135 |
-
with col1.container(border=True,height=
|
136 |
st.markdown("##### Compte rendu")
|
|
|
137 |
with st.container(height=650,border=False):
|
138 |
-
keywords_paragraph = f"### Mots clés extraits:\n- {audit['Mots clés'].strip()}"
|
139 |
st.markdown(keywords_paragraph)
|
140 |
st.write(cr)
|
141 |
col_copy , col_success = st.columns([1,11])
|
142 |
if col_copy.button("📋",key="copy_cr"):
|
143 |
-
|
|
|
|
|
144 |
col_success.success("Compte rendu copié dans le presse-papier")
|
145 |
|
146 |
-
with col2.container(border=True,height=
|
147 |
st.markdown("##### Dialoguer avec le CR")
|
148 |
|
149 |
user_query = st.chat_input("Par ici ...")
|
@@ -169,11 +173,12 @@ def doc_dialog_main():
|
|
169 |
wrapped_prompt = f'''Étant donné le contexte suivant {context} et le compte rendu du document {cr}, {last_message.content}'''
|
170 |
response = st.write_stream(generate_response_via_langchain(wrapped_prompt,stream=True))
|
171 |
st.session_state.cr_chat_history.append(AIMessage(content=response))
|
172 |
-
col_copy_c , col_success_c = st.columns([1,7])
|
173 |
-
if col_copy_c.button("📋",key="copy_cr_chat"):
|
|
|
174 |
chat_formatted = chat_history_formatter(st.session_state.cr_chat_history)
|
175 |
-
|
176 |
-
|
177 |
|
178 |
elif choice == "graphe de connaissance":
|
179 |
if "graph" not in st.session_state or st.session_state.graph == None:
|
@@ -202,7 +207,7 @@ def doc_dialog_main():
|
|
202 |
|
203 |
col1, col2 = st.columns([2.5, 1.5])
|
204 |
|
205 |
-
with col1.container(border=True,height=
|
206 |
st.write("##### Visualisation du graphe (**"+st.session_state.current_view+"**)")
|
207 |
filter_col,add_view_col,change_view_col,color_col = st.columns([9,1,1,1])
|
208 |
|
@@ -225,13 +230,14 @@ def doc_dialog_main():
|
|
225 |
|
226 |
selected = display_graph(edges,nodes,config)
|
227 |
|
228 |
-
col_copy , col_success = st.columns([1,11])
|
229 |
-
if col_copy.button("📋",key="copy_graph"):
|
|
|
230 |
graph_json = graph_doc_to_json(graph[0])
|
231 |
-
|
232 |
-
col_success.success("Graphe copié dans le presse-papier")
|
233 |
|
234 |
-
with col2.container(border=True,height=
|
235 |
st.markdown("##### Dialoguer avec le graphe")
|
236 |
|
237 |
user_query = st.chat_input("Par ici ...")
|
@@ -268,11 +274,12 @@ def doc_dialog_main():
|
|
268 |
for i,prompt in enumerate(prompts):
|
269 |
button = st.button(prompt,key=f"p_{i}",on_click=lambda i=i: st.session_state.chat_graph_history.append(HumanMessage(content=prompts[i])))
|
270 |
|
271 |
-
col_copy_c , col_success_c = st.columns([1,7])
|
272 |
-
if col_copy_c.button("📋",key="copy_graph_chat"):
|
|
|
273 |
chat_formatted = chat_history_formatter(st.session_state.chat_graph_history)
|
274 |
-
|
275 |
-
col_success_c.success("Historique copié !")
|
276 |
|
277 |
|
278 |
|
|
|
3 |
from utils.audit.rag import get_text_from_content_for_doc,get_text_from_content_for_audio
|
4 |
from utils.audit.response_llm import generate_response_via_langchain
|
5 |
from langchain_core.messages import AIMessage, HumanMessage
|
6 |
+
from st_copy_to_clipboard import st_copy_to_clipboard
|
7 |
from utils.kg.construct_kg import get_graph
|
8 |
from audit_page.knowledge_graph import *
|
9 |
+
import json
|
10 |
+
import clipboard
|
11 |
|
12 |
def graph_doc_to_json(graph):
|
13 |
nodes = []
|
|
|
134 |
if cr:
|
135 |
col1, col2 = st.columns([2.5, 1.5])
|
136 |
|
137 |
+
with col1.container(border=True,height=850):
|
138 |
st.markdown("##### Compte rendu")
|
139 |
+
keywords_paragraph = f"### Mots clés extraits:\n- {audit['Mots clés'].strip()}"
|
140 |
with st.container(height=650,border=False):
|
|
|
141 |
st.markdown(keywords_paragraph)
|
142 |
st.write(cr)
|
143 |
col_copy , col_success = st.columns([1,11])
|
144 |
if col_copy.button("📋",key="copy_cr"):
|
145 |
+
# with st.container(height=50,border=False):
|
146 |
+
# st_copy_to_clipboard(keywords_paragraph+"\n\n"+cr,key="cp_but_cr")
|
147 |
+
clipboard.copy(keywords_paragraph+"\n\n"+cr)
|
148 |
col_success.success("Compte rendu copié dans le presse-papier")
|
149 |
|
150 |
+
with col2.container(border=True,height=850):
|
151 |
st.markdown("##### Dialoguer avec le CR")
|
152 |
|
153 |
user_query = st.chat_input("Par ici ...")
|
|
|
173 |
wrapped_prompt = f'''Étant donné le contexte suivant {context} et le compte rendu du document {cr}, {last_message.content}'''
|
174 |
response = st.write_stream(generate_response_via_langchain(wrapped_prompt,stream=True))
|
175 |
st.session_state.cr_chat_history.append(AIMessage(content=response))
|
176 |
+
# col_copy_c , col_success_c = st.columns([1,7])
|
177 |
+
# if col_copy_c.button("📋",key="copy_cr_chat"):
|
178 |
+
with st.container(height=50,border=False):
|
179 |
chat_formatted = chat_history_formatter(st.session_state.cr_chat_history)
|
180 |
+
st_copy_to_clipboard(chat_formatted,key="cp_but_cr_chat")
|
181 |
+
# col_success_c.success("Historique copié !")
|
182 |
|
183 |
elif choice == "graphe de connaissance":
|
184 |
if "graph" not in st.session_state or st.session_state.graph == None:
|
|
|
207 |
|
208 |
col1, col2 = st.columns([2.5, 1.5])
|
209 |
|
210 |
+
with col1.container(border=True,height=850):
|
211 |
st.write("##### Visualisation du graphe (**"+st.session_state.current_view+"**)")
|
212 |
filter_col,add_view_col,change_view_col,color_col = st.columns([9,1,1,1])
|
213 |
|
|
|
230 |
|
231 |
selected = display_graph(edges,nodes,config)
|
232 |
|
233 |
+
# col_copy , col_success = st.columns([1,11])
|
234 |
+
# if col_copy.button("📋",key="copy_graph"):
|
235 |
+
with st.container(height=50,border=False):
|
236 |
graph_json = graph_doc_to_json(graph[0])
|
237 |
+
st_copy_to_clipboard(json.dumps(graph_json),key="cp_but_graph")
|
238 |
+
# col_success.success("Graphe copié dans le presse-papier")
|
239 |
|
240 |
+
with col2.container(border=True,height=850):
|
241 |
st.markdown("##### Dialoguer avec le graphe")
|
242 |
|
243 |
user_query = st.chat_input("Par ici ...")
|
|
|
274 |
for i,prompt in enumerate(prompts):
|
275 |
button = st.button(prompt,key=f"p_{i}",on_click=lambda i=i: st.session_state.chat_graph_history.append(HumanMessage(content=prompts[i])))
|
276 |
|
277 |
+
# col_copy_c , col_success_c = st.columns([1,7])
|
278 |
+
# if col_copy_c.button("📋",key="copy_graph_chat"):
|
279 |
+
with st.container(height=50,border=False):
|
280 |
chat_formatted = chat_history_formatter(st.session_state.chat_graph_history)
|
281 |
+
st_copy_to_clipboard(chat_formatted,key="cp_but_graph_chat")
|
282 |
+
# col_success_c.success("Historique copié !")
|
283 |
|
284 |
|
285 |
|
requirements.txt
CHANGED
@@ -23,4 +23,6 @@ python-dotenv
|
|
23 |
langchain-experimental
|
24 |
neo4j
|
25 |
streamlit-agraph
|
|
|
|
|
26 |
|
|
|
23 |
langchain-experimental
|
24 |
neo4j
|
25 |
streamlit-agraph
|
26 |
+
st-copy-to-clipboard
|
27 |
+
clipboard
|
28 |
|