Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,8 +78,7 @@ if uploaded_file is not None:
|
|
| 78 |
prs = Presentation()
|
| 79 |
|
| 80 |
for paragraph in paragraphs:
|
| 81 |
-
|
| 82 |
-
summary = summarizer(paragraph, max_length=(len(paragraph)/4), min_length=10, do_sample=False)
|
| 83 |
|
| 84 |
slide_layout = prs.slide_layouts[5] # Utilisez le modèle de diapositive approprié (index 5 pour une diapositive de titre et de contenu)
|
| 85 |
slide = prs.slides.add_slide(slide_layout)
|
|
@@ -95,23 +94,11 @@ if uploaded_file is not None:
|
|
| 95 |
image_height = slide_height * 0.7 # L'image occupe 70% de la hauteur de la slide
|
| 96 |
left_img = (slide_width - image_width) / 2 # Centrez horizontalement
|
| 97 |
top_img = (slide_height - image_height) * 0.6 # Occupe 15% de la hauteur en haut de la slide
|
| 98 |
-
|
| 99 |
-
#left = prs.slide_width * 0.1
|
| 100 |
-
#top = prs.slide_height * 0.6
|
| 101 |
-
#width = prs.slide_width * 0.8
|
| 102 |
-
#height = prs.slide_height * 0.3
|
| 103 |
-
#txBox = slide.shapes.add_textbox(left, top, width, height)
|
| 104 |
-
#tf = txBox.text_frame
|
| 105 |
-
#p = tf.add_paragraph()
|
| 106 |
-
#p.text = summary[0]['summary_text']
|
| 107 |
-
|
| 108 |
-
#st.text(f"Paragraphe {i}: {summary[0]['summary_text']}") # Affiche le résumé du paragraphe
|
| 109 |
|
| 110 |
image_bytes = query({
|
| 111 |
"inputs": 'A picture about :' + summary[0]['summary_text'] # Utilisez le texte du résumé
|
| 112 |
})
|
| 113 |
image = Image.open(io.BytesIO(image_bytes))
|
| 114 |
-
#left = top = prs.slide_width * 0.1
|
| 115 |
pic = slide.shapes.add_picture(io.BytesIO(image_bytes), left_img, top_img, image_width, image_height)
|
| 116 |
|
| 117 |
title_width = slide_width * 0.7 # Le titre occupe 70% de la largeur de la slide
|
|
@@ -121,10 +108,6 @@ if uploaded_file is not None:
|
|
| 121 |
title = slide.shapes.add_textbox(left_title, top_title, title_width, title_height)
|
| 122 |
title_frame = title.text_frame
|
| 123 |
|
| 124 |
-
#title_p = title_frame.add_paragraph()
|
| 125 |
-
#title_p.text = "Paragraphe {i}: "
|
| 126 |
-
#title_p.alignment = PP_ALIGN.CENTER # Centrez le texte horizontalement
|
| 127 |
-
|
| 128 |
text_width = slide_width * 0.7 # Le texte occupe 70% de la largeur de la slide
|
| 129 |
text_height = slide_height * 0.15 # Le texte occupe 15% de la hauteur de la slide
|
| 130 |
left_text = (slide_width - text_width) / 2 # Centrez horizontalement
|
|
@@ -135,34 +118,25 @@ if uploaded_file is not None:
|
|
| 135 |
p = tf.add_paragraph()
|
| 136 |
p.text = summary[0]['summary_text']
|
| 137 |
|
| 138 |
-
|
| 139 |
-
while p.space_after
|
| 140 |
-
p.font.size -= Pt(1) #
|
|
|
|
| 141 |
|
| 142 |
p.space_before = Pt(12) # Espace avant le paragraphe (12 points)
|
| 143 |
p.space_after = Pt(12) # Espace après le paragraphe (12 points)
|
| 144 |
p.alignment = PP_ALIGN.CENTER # Centrez le texte horizontalement
|
| 145 |
|
| 146 |
-
# Ajustez la largeur du cadre de texte du texte pour éviter le dépassement
|
| 147 |
text_frame_width = Pt(text_width - 2) # Réduisez la largeur de 0.1 pouce de chaque côté
|
| 148 |
-
#txBox.width = text_frame_width
|
| 149 |
txBox.text_frame.width = text_frame_width
|
| 150 |
|
| 151 |
-
# st.image(image)
|
| 152 |
-
|
| 153 |
i = i + 1
|
| 154 |
|
| 155 |
-
#tempfile_name = tempfile.NamedTemporaryFile(delete=False, suffix=".pptx").name
|
| 156 |
pptx_stream = io.BytesIO()
|
| 157 |
prs.save(pptx_stream)
|
| 158 |
pptx_stream.seek(0)
|
| 159 |
|
| 160 |
st.markdown(
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
#st.download_button("Télécharger la présentation", "output_path", key="download_pptx", mime="application/vnd.openxmlformats-officedocument.presentationml.presentation")
|
| 168 |
-
|
|
|
|
| 78 |
prs = Presentation()
|
| 79 |
|
| 80 |
for paragraph in paragraphs:
|
| 81 |
+
summary = summarizer(paragraph, max_length=(len(paragraph)//4), min_length=10, do_sample=False)
|
|
|
|
| 82 |
|
| 83 |
slide_layout = prs.slide_layouts[5] # Utilisez le modèle de diapositive approprié (index 5 pour une diapositive de titre et de contenu)
|
| 84 |
slide = prs.slides.add_slide(slide_layout)
|
|
|
|
| 94 |
image_height = slide_height * 0.7 # L'image occupe 70% de la hauteur de la slide
|
| 95 |
left_img = (slide_width - image_width) / 2 # Centrez horizontalement
|
| 96 |
top_img = (slide_height - image_height) * 0.6 # Occupe 15% de la hauteur en haut de la slide
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
image_bytes = query({
|
| 99 |
"inputs": 'A picture about :' + summary[0]['summary_text'] # Utilisez le texte du résumé
|
| 100 |
})
|
| 101 |
image = Image.open(io.BytesIO(image_bytes))
|
|
|
|
| 102 |
pic = slide.shapes.add_picture(io.BytesIO(image_bytes), left_img, top_img, image_width, image_height)
|
| 103 |
|
| 104 |
title_width = slide_width * 0.7 # Le titre occupe 70% de la largeur de la slide
|
|
|
|
| 108 |
title = slide.shapes.add_textbox(left_title, top_title, title_width, title_height)
|
| 109 |
title_frame = title.text_frame
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
text_width = slide_width * 0.7 # Le texte occupe 70% de la largeur de la slide
|
| 112 |
text_height = slide_height * 0.15 # Le texte occupe 15% de la hauteur de la slide
|
| 113 |
left_text = (slide_width - text_width) / 2 # Centrez horizontalement
|
|
|
|
| 118 |
p = tf.add_paragraph()
|
| 119 |
p.text = summary[0]['summary_text']
|
| 120 |
|
| 121 |
+
p.space_after = Pt(0) # Initialize space_after
|
| 122 |
+
while p.space_after < Pt(12):
|
| 123 |
+
p.font.size -= Pt(1) # Reduce the font size by 1 point
|
| 124 |
+
p.space_after = Pt(12) # Set space_after to 12 points again
|
| 125 |
|
| 126 |
p.space_before = Pt(12) # Espace avant le paragraphe (12 points)
|
| 127 |
p.space_after = Pt(12) # Espace après le paragraphe (12 points)
|
| 128 |
p.alignment = PP_ALIGN.CENTER # Centrez le texte horizontalement
|
| 129 |
|
|
|
|
| 130 |
text_frame_width = Pt(text_width - 2) # Réduisez la largeur de 0.1 pouce de chaque côté
|
|
|
|
| 131 |
txBox.text_frame.width = text_frame_width
|
| 132 |
|
|
|
|
|
|
|
| 133 |
i = i + 1
|
| 134 |
|
|
|
|
| 135 |
pptx_stream = io.BytesIO()
|
| 136 |
prs.save(pptx_stream)
|
| 137 |
pptx_stream.seek(0)
|
| 138 |
|
| 139 |
st.markdown(
|
| 140 |
+
f'<a href="data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64,{base64.b64encode(pptx_stream.read()).decode()}" download="presentation.pptx">Télécharger la présentation</a>',
|
| 141 |
+
unsafe_allow_html=True,
|
| 142 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|