Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import fitz # Utilisation de PyMuPDF (PdfReader) pour extraire le texte depuis le PDF
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Titre de l'application
|
| 9 |
-
st.title("Afficher
|
| 10 |
|
| 11 |
# Section d'upload de fichier PDF
|
| 12 |
uploaded_file = st.file_uploader("Sélectionnez un fichier PDF", type=["pdf"])
|
|
@@ -22,10 +24,15 @@ if uploaded_file is not None:
|
|
| 22 |
for page_number in range(pdf_document.page_count):
|
| 23 |
page = pdf_document.load_page(page_number)
|
| 24 |
page_text = page.get_text()
|
| 25 |
-
page_paragraphs =
|
| 26 |
paragraphs.extend(page_paragraphs)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import fitz # Utilisation de PyMuPDF (PdfReader) pour extraire le texte depuis le PDF
|
| 3 |
|
| 4 |
+
# Fonction pour extraire les longs paragraphes à partir du texte
|
| 5 |
+
def extraire_long_paragraphes(texte, longueur_minimale=100):
|
| 6 |
+
paragraphes = texte.split("\n\n") # Divise le texte en paragraphes en utilisant des doubles sauts de ligne
|
| 7 |
+
longs_paragraphes = [paragraphe.strip() for paragraphe in paragraphes if len(paragraphe) >= longueur_minimale]
|
| 8 |
+
return "\n\n".join(longs_paragraphes)
|
| 9 |
|
| 10 |
# Titre de l'application
|
| 11 |
+
st.title("Afficher les longs paragraphes d'un fichier PDF")
|
| 12 |
|
| 13 |
# Section d'upload de fichier PDF
|
| 14 |
uploaded_file = st.file_uploader("Sélectionnez un fichier PDF", type=["pdf"])
|
|
|
|
| 24 |
for page_number in range(pdf_document.page_count):
|
| 25 |
page = pdf_document.load_page(page_number)
|
| 26 |
page_text = page.get_text()
|
| 27 |
+
page_paragraphs = page_text.split("\n\n") # Divisez en paragraphes
|
| 28 |
paragraphs.extend(page_paragraphs)
|
| 29 |
|
| 30 |
+
# Concaténez les paragraphes en un seul texte
|
| 31 |
+
full_text = "\n\n".join(paragraphs)
|
| 32 |
+
|
| 33 |
+
# Utilisez la fonction pour extraire les longs paragraphes
|
| 34 |
+
longs_paragraphes = extraire_long_paragraphes(full_text, longueur_minimale=200)
|
| 35 |
+
|
| 36 |
+
# Affichez les longs paragraphes extraits
|
| 37 |
+
st.subheader("Longs paragraphes du PDF:")
|
| 38 |
+
st.text(longs_paragraphes)
|