LaurentTRIPIED commited on
Commit
eb71392
·
verified ·
1 Parent(s): ac854f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -33,15 +33,25 @@ with tab1:
33
  pdf_path = 'data/07-VF2_UDM_Oneframe_A4-2023.pdf'
34
  json_output_path = 'data/extracted_text.json'
35
 
36
- if st.button('Extraire le texte du PDF et sauvegarder en JSON', key='extract'):
37
- pdf_text = extract_text_from_pdf(pdf_path)
38
- save_text_to_json(pdf_text, json_output_path)
39
- st.success("Le texte a été extrait et sauvegardé.")
40
- try:
41
- with open(json_output_path, 'r', encoding='utf-8') as f:
42
- st.download_button("Télécharger le JSON", f, "extracted_text.json", "application/json")
43
- except FileNotFoundError:
44
- st.error("Le fichier n'a pas pu être créé ou trouvé.")
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Onglet 2 - Questions Chatbot
47
  with tab2:
 
33
  pdf_path = 'data/07-VF2_UDM_Oneframe_A4-2023.pdf'
34
  json_output_path = 'data/extracted_text.json'
35
 
36
+ if not os.path.exists(json_output_path):
37
+ if st.button('Extraire le texte du PDF et sauvegarder en JSON'):
38
+ pdf_text = extract_text_from_pdf(pdf_path)
39
+ save_text_to_json(pdf_text, json_output_path)
40
+ st.success("Le texte a été extrait et sauvegardé.")
41
+ else:
42
+ st.success(f"Le fichier {json_output_path} existe déjà. Aucune extraction nécessaire.")
43
+
44
+ try:
45
+ with open(json_output_path, 'r', encoding='utf-8') as f:
46
+ st.download_button(
47
+ label="Télécharger le JSON",
48
+ data=f,
49
+ file_name="extracted_text.json",
50
+ mime="application/json"
51
+ )
52
+ except FileNotFoundError:
53
+ st.error(f"Le fichier {json_output_path} n'est pas disponible pour téléchargement.")
54
+
55
 
56
  # Onglet 2 - Questions Chatbot
57
  with tab2: