Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,9 @@ import os
|
|
| 8 |
import requests
|
| 9 |
import io
|
| 10 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
| 13 |
headers = {"Authorization": "Bearer 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"}
|
|
@@ -69,17 +72,42 @@ if uploaded_file is not None:
|
|
| 69 |
pdf_data = uploaded_file.read()
|
| 70 |
|
| 71 |
paragraphs = extract_paragraphs_by_vertical_spacing(pdf_data)
|
| 72 |
-
i = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
for paragraph in paragraphs:
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
image_bytes = query({
|
| 79 |
-
"inputs": 'A picture about
|
| 80 |
})
|
| 81 |
image = Image.open(io.BytesIO(image_bytes))
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
|
|
|
|
|
|
|
|
|
| 8 |
import requests
|
| 9 |
import io
|
| 10 |
from PIL import Image
|
| 11 |
+
from pptx import Presentation
|
| 12 |
+
from pptx.util import Inches
|
| 13 |
+
import tempfile
|
| 14 |
|
| 15 |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
| 16 |
headers = {"Authorization": "Bearer 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"}
|
|
|
|
| 72 |
pdf_data = uploaded_file.read()
|
| 73 |
|
| 74 |
paragraphs = extract_paragraphs_by_vertical_spacing(pdf_data)
|
| 75 |
+
i = 1
|
| 76 |
+
|
| 77 |
+
# Create a PowerPoint presentation
|
| 78 |
+
prs = Presentation()
|
| 79 |
+
|
| 80 |
for paragraph in paragraphs:
|
| 81 |
+
summary = summarizer(paragraph, max_length=(len(paragraph) / 2), min_length=10, do_sample=False)
|
| 82 |
+
|
| 83 |
+
# Create a slide
|
| 84 |
+
slide = prs.slides.add_slide(prs.slide_layouts[5])
|
| 85 |
+
|
| 86 |
+
# Add the paragraph to the slide
|
| 87 |
+
left = top = Inches(1)
|
| 88 |
+
width = height = Inches(5)
|
| 89 |
+
txBox = slide.shapes.add_textbox(left, top, width, height)
|
| 90 |
+
tf = txBox.text_frame
|
| 91 |
+
p = tf.add_paragraph()
|
| 92 |
+
p.text = f"Paragraph {i}:"
|
| 93 |
+
p.space_after = Inches(0.1)
|
| 94 |
+
p = tf.add_paragraph()
|
| 95 |
+
p.text = summary[0]['summary_text']
|
| 96 |
+
|
| 97 |
+
# Generate and add the image to the slide
|
| 98 |
image_bytes = query({
|
| 99 |
+
"inputs": 'A picture without text about: ' + summary[0]['summary_text']
|
| 100 |
})
|
| 101 |
image = Image.open(io.BytesIO(image_bytes))
|
| 102 |
+
temp_img_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
|
| 103 |
+
image.save(temp_img_path)
|
| 104 |
+
slide.shapes.add_picture(temp_img_path, Inches(1), Inches(1.5), Inches(5), Inches(3))
|
| 105 |
+
|
| 106 |
+
i += 1
|
| 107 |
|
| 108 |
+
# Save the PowerPoint presentation
|
| 109 |
+
presentation_path = tempfile.NamedTemporaryFile(delete=False, suffix=".pptx").name
|
| 110 |
+
prs.save(presentation_path)
|
| 111 |
|
| 112 |
+
# Display the link to download the PowerPoint file
|
| 113 |
+
st.markdown(f"Download the PowerPoint presentation: [PowerPoint File]({presentation_path})")
|