yannESGI commited on
Commit
5f2f34a
·
1 Parent(s): 2373446

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -28
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
- summary_text = add_line_breaks_to_summary(summary[0]['summary_text'], 80)
96
-
97
- # Generate and save the image to a temporary file
98
- image_bytes = query({
99
- "inputs": 'A picture without text about: ' + summary[0]['summary_text']
100
- })
101
- temp_img_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
102
- with open(temp_img_path, "wb") as img_file:
103
- img_file.write(image_bytes)
104
-
105
- # Create a slide
106
- slide = prs.slides.add_slide(prs.slide_layouts[5])
107
-
108
- # Add the image to the slide at the bottom with a 0.5-inch space
109
- left = (prs.slide_width - Inches(3)) / 2
110
- top = prs.slide_height - Inches(3) - Inches(0.5) # Adjusted for the 0.5-inch space
111
- pic = slide.shapes.add_picture(temp_img_path, left, top, Inches(3), Inches(3))
112
-
113
- # Add the paragraph to the slide at the top
114
- left = Inches(1)
115
- top = Inches(1)
116
- width = Inches(8) # Adjust the width as needed
117
- height = Inches(2) # Adjust the height as needed
118
- txBox = slide.shapes.add_textbox(left, top, width, height)
119
- tf = txBox.text_frame
120
- p = tf.add_paragraph()
121
- p.text = summary_text
122
- p.space_after = Pt(0) # Adjust the spacing as needed
 
 
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