Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,16 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import requests
|
| 3 |
import streamlit as st
|
| 4 |
import fitz # Utilisation de PyMuPDF (PdfReader) pour extraire le texte depuis le PDF
|
| 5 |
from transformers import pipeline
|
|
|
|
|
|
|
| 6 |
import io
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
| 10 |
headers = {"Authorization": "Bearer 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"}
|
|
|
|
| 11 |
|
| 12 |
-
def query(payload):
|
| 13 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 14 |
-
return response.content
|
| 15 |
|
| 16 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 17 |
|
| 18 |
# Fonction pour extraire les longs paragraphes à partir du texte
|
| 19 |
def extraire_long_paragraphes(texte, longueur_maximale=999):
|
|
@@ -21,6 +18,10 @@ def extraire_long_paragraphes(texte, longueur_maximale=999):
|
|
| 21 |
longs_paragraphes = [paragraphe.strip() for paragraphe in paragraphes if len(paragraphe) >= longueur_maximale]
|
| 22 |
return longs_paragraphes
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Titre de l'application
|
| 25 |
st.title("PDF2SLIDE")
|
| 26 |
|
|
@@ -45,17 +46,13 @@ if uploaded_file is not None:
|
|
| 45 |
longs_paragraphes = extraire_long_paragraphes("\n\n".join(paragraphs), longueur_maximale=1000)
|
| 46 |
|
| 47 |
# Affichez les longs paragraphes extraits avec des numéros et des résumés
|
| 48 |
-
|
|
|
|
| 49 |
for i, paragraphe in enumerate(longs_paragraphes, start=1):
|
| 50 |
-
# Générer un résumé
|
| 51 |
summary = summarizer(paragraphe, max_length=900, min_length=30, do_sample=False)
|
| 52 |
-
|
| 53 |
-
# Générer une image à partir du paragraphe
|
| 54 |
image_bytes = query({
|
| 55 |
-
|
| 56 |
})
|
| 57 |
image = Image.open(io.BytesIO(image_bytes))
|
| 58 |
-
|
| 59 |
-
# Afficher le paragraphe, le résumé et l'image générée
|
| 60 |
-
st.text(f"Paragraphe {i}: {summary[0]['summary_text']}")
|
| 61 |
st.image(image)
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import fitz # Utilisation de PyMuPDF (PdfReader) pour extraire le texte depuis le PDF
|
| 3 |
from transformers import pipeline
|
| 4 |
+
import os
|
| 5 |
+
import requests
|
| 6 |
import io
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
| 10 |
headers = {"Authorization": "Bearer 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"}
|
| 11 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
|
| 15 |
# Fonction pour extraire les longs paragraphes à partir du texte
|
| 16 |
def extraire_long_paragraphes(texte, longueur_maximale=999):
|
|
|
|
| 18 |
longs_paragraphes = [paragraphe.strip() for paragraphe in paragraphes if len(paragraphe) >= longueur_maximale]
|
| 19 |
return longs_paragraphes
|
| 20 |
|
| 21 |
+
def query(payload):
|
| 22 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 23 |
+
return response.content
|
| 24 |
+
|
| 25 |
# Titre de l'application
|
| 26 |
st.title("PDF2SLIDE")
|
| 27 |
|
|
|
|
| 46 |
longs_paragraphes = extraire_long_paragraphes("\n\n".join(paragraphs), longueur_maximale=1000)
|
| 47 |
|
| 48 |
# Affichez les longs paragraphes extraits avec des numéros et des résumés
|
| 49 |
+
# Affichez les longs paragraphes extraits avec des numéros et des résumés
|
| 50 |
+
st.subheader("Longs paragraphes du PDF avec résumé:")
|
| 51 |
for i, paragraphe in enumerate(longs_paragraphes, start=1):
|
|
|
|
| 52 |
summary = summarizer(paragraphe, max_length=900, min_length=30, do_sample=False)
|
| 53 |
+
#st.text(f"Paragraphe {i}: {summary[0]['summary_text']}") # Use summary[0]['summary_text']
|
|
|
|
| 54 |
image_bytes = query({
|
| 55 |
+
"inputs": summary,
|
| 56 |
})
|
| 57 |
image = Image.open(io.BytesIO(image_bytes))
|
|
|
|
|
|
|
|
|
|
| 58 |
st.image(image)
|