update code
Browse files- app.py +17 -5
- files.csv +7 -7
- prompt-history.pkl +3 -0
app.py
CHANGED
@@ -3,19 +3,24 @@ from tempfile import NamedTemporaryFile
|
|
3 |
import pandas as pd
|
4 |
import streamlit as st
|
5 |
from pdf2image import convert_from_path
|
6 |
-
|
7 |
from core import init_llm, invoke
|
|
|
8 |
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
11 |
# LLM initialization
|
12 |
init_llm()
|
13 |
PROOF_LIMIT_SIZE = 296
|
|
|
14 |
|
15 |
def get_llm_response(input_text):
|
16 |
response = invoke(input_text)
|
17 |
return response
|
18 |
|
|
|
|
|
|
|
|
|
19 |
def get_all_external_files():
|
20 |
all_files = pd.read_csv("./files.csv", sep=";")
|
21 |
res = []
|
@@ -34,7 +39,8 @@ def show_all_external_files():
|
|
34 |
if row["tags"] in options:
|
35 |
st.write(f"<a href=\'{row['external-link']}\'>{row['name']}</a>", unsafe_allow_html=True)
|
36 |
|
37 |
-
def click_proof(lien):
|
|
|
38 |
path_to_file = None
|
39 |
for _, f in all_files.iterrows():
|
40 |
stemed_fn = Path(f["internal-link"].split("/")[-1]).stem
|
@@ -57,21 +63,26 @@ def show_pdf(link, page_num):
|
|
57 |
tmp_f_name = NamedTemporaryFile(delete=False)
|
58 |
pdf_images.save(tmp_f_name.name, 'PNG')
|
59 |
st.session_state.messages.append({"role": "ai", "content": tmp_f_name.name})
|
|
|
60 |
print(f"Successfully converted PDF ({link} page {page_num}) to images ({tmp_f_name.name})")
|
61 |
|
62 |
def update_proofs(proofs):
|
63 |
if len(proofs):
|
64 |
proofs = proofs[-1]
|
65 |
for it, (proof, source) in enumerate(zip(proofs["justifications"], proofs["sources"])):
|
66 |
-
print(source)
|
67 |
limited_content = f"[{it+1}] - {proof[:min(PROOF_LIMIT_SIZE, len(proof))]} ..."
|
68 |
-
st.button(limited_content, on_click=click_proof, use_container_width=True, kwargs={"lien": source})
|
69 |
|
70 |
all_files = get_all_external_files()
|
71 |
|
72 |
# Initialize chat history
|
73 |
if "messages" not in st.session_state:
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
if "proof" not in st.session_state:
|
77 |
st.session_state.proofs = []
|
@@ -124,6 +135,7 @@ with column_chat:
|
|
124 |
"sources": response["sources"]
|
125 |
|
126 |
})
|
|
|
127 |
with placeholder.chat_message("assistant"):
|
128 |
st.markdown(response["content"])
|
129 |
with column_proof:
|
|
|
3 |
import pandas as pd
|
4 |
import streamlit as st
|
5 |
from pdf2image import convert_from_path
|
|
|
6 |
from core import init_llm, invoke
|
7 |
+
import pickle
|
8 |
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
11 |
# LLM initialization
|
12 |
init_llm()
|
13 |
PROOF_LIMIT_SIZE = 296
|
14 |
+
HISTORY_FILE_NAME = "prompt-history.pkl"
|
15 |
|
16 |
def get_llm_response(input_text):
|
17 |
response = invoke(input_text)
|
18 |
return response
|
19 |
|
20 |
+
def save_history():
|
21 |
+
with open(HISTORY_FILE_NAME, "wb") as fn:
|
22 |
+
pickle.dump(st.session_state.messages, fn)
|
23 |
+
|
24 |
def get_all_external_files():
|
25 |
all_files = pd.read_csv("./files.csv", sep=";")
|
26 |
res = []
|
|
|
39 |
if row["tags"] in options:
|
40 |
st.write(f"<a href=\'{row['external-link']}\'>{row['name']}</a>", unsafe_allow_html=True)
|
41 |
|
42 |
+
def click_proof(lien, full_content):
|
43 |
+
st.session_state.messages.append({"role": "assistant", "content": full_content})
|
44 |
path_to_file = None
|
45 |
for _, f in all_files.iterrows():
|
46 |
stemed_fn = Path(f["internal-link"].split("/")[-1]).stem
|
|
|
63 |
tmp_f_name = NamedTemporaryFile(delete=False)
|
64 |
pdf_images.save(tmp_f_name.name, 'PNG')
|
65 |
st.session_state.messages.append({"role": "ai", "content": tmp_f_name.name})
|
66 |
+
save_history()
|
67 |
print(f"Successfully converted PDF ({link} page {page_num}) to images ({tmp_f_name.name})")
|
68 |
|
69 |
def update_proofs(proofs):
|
70 |
if len(proofs):
|
71 |
proofs = proofs[-1]
|
72 |
for it, (proof, source) in enumerate(zip(proofs["justifications"], proofs["sources"])):
|
|
|
73 |
limited_content = f"[{it+1}] - {proof[:min(PROOF_LIMIT_SIZE, len(proof))]} ..."
|
74 |
+
st.button(limited_content, on_click=click_proof, use_container_width=True, kwargs={"lien": source, "full_content": proof})
|
75 |
|
76 |
all_files = get_all_external_files()
|
77 |
|
78 |
# Initialize chat history
|
79 |
if "messages" not in st.session_state:
|
80 |
+
if Path(HISTORY_FILE_NAME).is_file():
|
81 |
+
with open(HISTORY_FILE_NAME, "rb") as fn:
|
82 |
+
history = pickle.load(fn)
|
83 |
+
else:
|
84 |
+
history = []
|
85 |
+
st.session_state.messages = history
|
86 |
|
87 |
if "proof" not in st.session_state:
|
88 |
st.session_state.proofs = []
|
|
|
135 |
"sources": response["sources"]
|
136 |
|
137 |
})
|
138 |
+
save_history()
|
139 |
with placeholder.chat_message("assistant"):
|
140 |
st.markdown(response["content"])
|
141 |
with column_proof:
|
files.csv
CHANGED
@@ -4,19 +4,19 @@ data/Elevage bovin/Aides/Dossier-PAC-2022_notice_generalites.pdf;https://www.tel
|
|
4 |
data/Elevage bovin/Aides/Dossier-PAC-2022_notice_ICHN.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tas/2022/Dossier-PAC-2022_notice_ICHN.pdf;Elevage bovin; PAC 2022 - Notice ICHN
|
5 |
data/Elevage bovin/Aides/Dossier-PAC-2022_notice_SIE.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tas/2022/Dossier-PAC-2022_notice_SIE.pdf;Elevage bovin;PAC 2022 - Notice SIE
|
6 |
data/Elevage bovin/Aides/Dossier-PAC-2022_notice_assurance-recolte.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tas/2022/Dossier-PAC-2022_notice_assurance-recolte.pdf;Elevage bovin;PAC 2022 - Notice assurance recolte
|
7 |
-
data/Elevage bovin/Aides/Quelles aides peuvent toucher les
|
8 |
data/Elevage bovin/Aides/RPB-2022_dotation_JA.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tdp/2022/RPB-2022_dotation_JA.pdf;Elevage bovin;RPB 2022 - dotation JA
|
9 |
data/Elevage bovin/Aides/Publication-beneficiaires-2022_notice-mesures.pdf;https://www.telepac.agriculture.gouv.fr/telepac/tbp/doc/Publication-beneficiaires-2022_notice-mesures.pdf;Elevage bovin;Publication beneficiaires 2022 - Notice mesures
|
10 |
data/Elevage bovin/Aides/VSLM-2022_notice.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/taa/2022/VSLM-2022_notice.pdf;Elevage bovin;VSLM 2022 - Notice
|
11 |
-
data/Elevage bovin/Bien
|
12 |
data/Elevage bovin/Gestion des effluents/livret_explicatif_gestion_effluents_elevage.pdf;https://bourgognefranchecomte.chambres-agriculture.fr/fileadmin/user_upload/Bourgogne-Franche-Comte/061_Inst-Bourgogne-Franche-Comte/CA39/actus_agenda/livret_explicatif_gestion_effluents_elevage.pdf;Elevage bovin;Livret explicatif gestion effluents elevage
|
13 |
data/Elevage bovin/Gestion des effluents/reglementation-valorisation-agronomique-effluents-elevage.pdf;https://www.itbfr.org/fileadmin/20210521163933Valorisation_agronomique_rmt_enviro_web.pdf;Elevage bovin;Reglementation valorisation agronomique effluents elevage
|
14 |
-
data/Elevage bovin/
|
15 |
-
data/Elevage bovin/
|
16 |
-
data/Elevage bovin/
|
17 |
data/Elevage bovin/Installations/Fiches-batiment-agricole-detail-construction.pdf;https://hautsdefrance.chambres-agriculture.fr/fileadmin/user_upload/National/FAL_commun/publications/Hauts-de-France/Fiches-batiment-agricole-detail-construction.pdf;Elevage bovin;Fiches batiment agricole detail construction
|
18 |
-
data/Elevage bovin/Installations/Mettre en
|
19 |
data/Elevage bovin/Maladies/CELEX_32016R0429_FR_TXT.pdf;https://eur-lex.europa.eu/legal-content/FR/TXT/PDF/?uri=CELEX:32016R0429;Elevage bovin;CELEX 32016R0429
|
20 |
-
data/Elevage bovin/Je suis
|
21 |
data/Cultures/Soja/RT-annexe-de-la-production-du-controle-et-de-la-certification-des-semences-de-soja.pdf;https://www.semae.fr/uploads/bases_gnis/reglements_techniques/RT-annexe-de-la-production-du-controle-et-de-la-certification-des-semences-de-soja.pdf;Cultures;RT annexe de la production du controle et de la certification des semences de soja
|
22 |
data/Cultures/Soja/charte-soja-de-france-v1-avril2018.pdf;https://www.terresunivia.fr/sites/default/files/Charte%20Soja%20de%20France/charte-soja-de-france-v1-avril2018.pdf;Cultures;charte soja de France v1 avril2018
|
|
|
4 |
data/Elevage bovin/Aides/Dossier-PAC-2022_notice_ICHN.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tas/2022/Dossier-PAC-2022_notice_ICHN.pdf;Elevage bovin; PAC 2022 - Notice ICHN
|
5 |
data/Elevage bovin/Aides/Dossier-PAC-2022_notice_SIE.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tas/2022/Dossier-PAC-2022_notice_SIE.pdf;Elevage bovin;PAC 2022 - Notice SIE
|
6 |
data/Elevage bovin/Aides/Dossier-PAC-2022_notice_assurance-recolte.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tas/2022/Dossier-PAC-2022_notice_assurance-recolte.pdf;Elevage bovin;PAC 2022 - Notice assurance recolte
|
7 |
+
data/Elevage bovin/Aides/Quelles aides peuvent toucher les éleveurs.pdf;https://www.francetvinfo.fr/economie/emploi/metiers/agriculture/crise-des-eleveurs/quelles-aides-peuvent-toucher-les-eleveurs_1008373.html;Elevage bovin;Quelles aides peuvent toucher les éleveurs?
|
8 |
data/Elevage bovin/Aides/RPB-2022_dotation_JA.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/tdp/2022/RPB-2022_dotation_JA.pdf;Elevage bovin;RPB 2022 - dotation JA
|
9 |
data/Elevage bovin/Aides/Publication-beneficiaires-2022_notice-mesures.pdf;https://www.telepac.agriculture.gouv.fr/telepac/tbp/doc/Publication-beneficiaires-2022_notice-mesures.pdf;Elevage bovin;Publication beneficiaires 2022 - Notice mesures
|
10 |
data/Elevage bovin/Aides/VSLM-2022_notice.pdf;https://www.telepac.agriculture.gouv.fr/telepac/pdf/taa/2022/VSLM-2022_notice.pdf;Elevage bovin;VSLM 2022 - Notice
|
11 |
+
data/Elevage bovin/Bien être animal/Directive-98-58-CE.pdf;https://www.interbev.fr/wp-content/uploads/2018/07/Directive-98-58-CE.pdf;Elevage bovin;Directive 98 58 CE
|
12 |
data/Elevage bovin/Gestion des effluents/livret_explicatif_gestion_effluents_elevage.pdf;https://bourgognefranchecomte.chambres-agriculture.fr/fileadmin/user_upload/Bourgogne-Franche-Comte/061_Inst-Bourgogne-Franche-Comte/CA39/actus_agenda/livret_explicatif_gestion_effluents_elevage.pdf;Elevage bovin;Livret explicatif gestion effluents elevage
|
13 |
data/Elevage bovin/Gestion des effluents/reglementation-valorisation-agronomique-effluents-elevage.pdf;https://www.itbfr.org/fileadmin/20210521163933Valorisation_agronomique_rmt_enviro_web.pdf;Elevage bovin;Reglementation valorisation agronomique effluents elevage
|
14 |
+
data/Elevage bovin/Identification_Traçabilité/Arrêté du 6 août 2013 relatif à l'identification des animaux de l'espèce bovine - Légifrance.pdf;https://www.legifrance.gouv.fr/loda/id/JORFTEXT000027876223;Elevage bovin;Arrêté du 6 août 2013 relatif à l'identification des animaux de l'espèce bovine
|
15 |
+
data/Elevage bovin/Identification_Traçabilité/CELEX_32021R0520_FR_TXT.pdf;https://eur-lex.europa.eu/legal-content/FR/TXT/PDF/?uri=CELEX:32021R0520;Elevage bovin;CELEX 32021R0520
|
16 |
+
data/Elevage bovin/Identification_Traçabilité/identification_des_bovins.pdf;https://agriculture.gouv.fr/telecharger/130363;Elevage bovin;Identification des bovins
|
17 |
data/Elevage bovin/Installations/Fiches-batiment-agricole-detail-construction.pdf;https://hautsdefrance.chambres-agriculture.fr/fileadmin/user_upload/National/FAL_commun/publications/Hauts-de-France/Fiches-batiment-agricole-detail-construction.pdf;Elevage bovin;Fiches batiment agricole detail construction
|
18 |
+
data/Elevage bovin/Installations/Mettre en conformité son atelier élevage - Chambre d'agriculture Meurthe-et-Moselle.pdf;https://meurthe-et-moselle.chambre-agriculture.fr/environnement/reglementation/mettre-en-conformite-son-atelier-elevage/;Elevage bovin;Mettre en conformité son atelier élevage
|
19 |
data/Elevage bovin/Maladies/CELEX_32016R0429_FR_TXT.pdf;https://eur-lex.europa.eu/legal-content/FR/TXT/PDF/?uri=CELEX:32016R0429;Elevage bovin;CELEX 32016R0429
|
20 |
+
data/Elevage bovin/Je suis détenteur de bovins, quelles obligations sanitaires _ _ DRAAF Occitanie.pdf;https://draaf.occitanie.agriculture.gouv.fr/je-suis-detenteur-de-bovins-quelles-obligations-sanitaires-a286.html;Elevage bovin;Je suis détenteur de bovins, quelles obligations sanitaires?
|
21 |
data/Cultures/Soja/RT-annexe-de-la-production-du-controle-et-de-la-certification-des-semences-de-soja.pdf;https://www.semae.fr/uploads/bases_gnis/reglements_techniques/RT-annexe-de-la-production-du-controle-et-de-la-certification-des-semences-de-soja.pdf;Cultures;RT annexe de la production du controle et de la certification des semences de soja
|
22 |
data/Cultures/Soja/charte-soja-de-france-v1-avril2018.pdf;https://www.terresunivia.fr/sites/default/files/Charte%20Soja%20de%20France/charte-soja-de-france-v1-avril2018.pdf;Cultures;charte soja de France v1 avril2018
|
prompt-history.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:829c1fd1ab9a3bc060128e0118ff527c289eb1e013331b30edaf3cfc88f06085
|
3 |
+
size 1292
|