Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,35 +91,38 @@ if uploaded_file is not None:
|
|
| 91 |
prs = Presentation()
|
| 92 |
|
| 93 |
for paragraph in paragraphs:
|
|
|
|
| 94 |
summary = summarizer(paragraph, max_length=(round(len(paragraph) / 2)), min_length=10, do_sample=False)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Save the PowerPoint presentation
|
| 125 |
presentation_path = tempfile.NamedTemporaryFile(delete=False, suffix=".pptx").name
|
|
|
|
| 91 |
prs = Presentation()
|
| 92 |
|
| 93 |
for paragraph in paragraphs:
|
| 94 |
+
|
| 95 |
summary = summarizer(paragraph, max_length=(round(len(paragraph) / 2)), min_length=10, do_sample=False)
|
| 96 |
+
if summary and summary[0].get('summary_text'):
|
| 97 |
+
summary_text = add_line_breaks_to_summary(summary[0]['summary_text'], 80)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# Generate and save the image to a temporary file
|
| 101 |
+
image_bytes = query({
|
| 102 |
+
"inputs": 'A picture without text about: ' + summary[0]['summary_text']
|
| 103 |
+
})
|
| 104 |
+
temp_img_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
|
| 105 |
+
with open(temp_img_path, "wb") as img_file:
|
| 106 |
+
img_file.write(image_bytes)
|
| 107 |
+
|
| 108 |
+
# Create a slide
|
| 109 |
+
slide = prs.slides.add_slide(prs.slide_layouts[5])
|
| 110 |
+
|
| 111 |
+
# Add the image to the slide at the bottom with a 0.5-inch space
|
| 112 |
+
left = (prs.slide_width - Inches(3)) / 2
|
| 113 |
+
top = prs.slide_height - Inches(3) - Inches(0.5) # Adjusted for the 0.5-inch space
|
| 114 |
+
pic = slide.shapes.add_picture(temp_img_path, left, top, Inches(3), Inches(3))
|
| 115 |
+
|
| 116 |
+
# Add the paragraph to the slide at the top
|
| 117 |
+
left = Inches(1)
|
| 118 |
+
top = Inches(1)
|
| 119 |
+
width = Inches(8) # Adjust the width as needed
|
| 120 |
+
height = Inches(2) # Adjust the height as needed
|
| 121 |
+
txBox = slide.shapes.add_textbox(left, top, width, height)
|
| 122 |
+
tf = txBox.text_frame
|
| 123 |
+
p = tf.add_paragraph()
|
| 124 |
+
p.text = summary_text
|
| 125 |
+
p.space_after = Pt(0) # Adjust the spacing as needed
|
| 126 |
|
| 127 |
# Save the PowerPoint presentation
|
| 128 |
presentation_path = tempfile.NamedTemporaryFile(delete=False, suffix=".pptx").name
|