Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
|
|
|
|
|
| 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 |
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
|
@@ -34,9 +45,17 @@ if uploaded_file is not None:
|
|
| 34 |
longs_paragraphes = extraire_long_paragraphes("\n\n".join(paragraphs), longueur_maximale=1000)
|
| 35 |
|
| 36 |
# Affichez les longs paragraphes extraits avec des numéros et des résumés
|
| 37 |
-
|
| 38 |
-
st.subheader("Longs paragraphes du PDF avec résumé:")
|
| 39 |
for i, paragraphe in enumerate(longs_paragraphes, start=1):
|
|
|
|
| 40 |
summary = summarizer(paragraphe, max_length=900, min_length=30, do_sample=False)
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 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 |
+
st.subheader("Longs paragraphes du PDF avec résumé et image générée:")
|
|
|
|
| 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 |
+
"inputs": paragraphe,
|
| 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)
|