Update python_pptx/python_pptx.py
Browse files- python_pptx/python_pptx.py +22 -9
python_pptx/python_pptx.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# https://huggingface.co/spaces/MisterAI/GenDoc_05
|
| 3 |
-
# /home/user/python_pptx/python_pptx.
|
| 4 |
|
| 5 |
from pptx import Presentation
|
| 6 |
from pptx.util import Inches, Pt
|
|
@@ -38,12 +38,12 @@ class PresentationGenerator:
|
|
| 38 |
elif line.startswith("## Titre:"):
|
| 39 |
if current_slide:
|
| 40 |
current_slide['title'] = line[8:].strip()
|
| 41 |
-
elif line.startswith("###
|
| 42 |
if current_slide:
|
| 43 |
-
current_slide['points']
|
| 44 |
elif line.startswith("- ") and current_slide:
|
| 45 |
if current_slide:
|
| 46 |
-
current_slide['points'].append(line[2:].strip())
|
| 47 |
elif line == "#Fin Slide Ressources Utiles#" or line.startswith("#Fin Slide"):
|
| 48 |
if current_slide:
|
| 49 |
slides.append(current_slide)
|
|
@@ -55,7 +55,7 @@ class PresentationGenerator:
|
|
| 55 |
prs = Presentation()
|
| 56 |
|
| 57 |
# Determine the maximum content slide for font size adjustment
|
| 58 |
-
max_content_length = max(len(" ".join(slide['points'])) for slide in slides if slide['type'] == 'content')
|
| 59 |
|
| 60 |
# Set font sizes based on the maximum content length
|
| 61 |
base_font_size = 32
|
|
@@ -87,11 +87,24 @@ class PresentationGenerator:
|
|
| 87 |
if slide['points']:
|
| 88 |
body = content_slide.shapes.placeholders[1].text_frame
|
| 89 |
body.clear()
|
| 90 |
-
for point in slide['points']:
|
| 91 |
p = body.add_paragraph()
|
| 92 |
-
p.text = point
|
| 93 |
-
p.font.size = Pt(base_font_size)
|
| 94 |
p.font.name = self.default_font
|
| 95 |
-
p.font.color.rgb = self.default_theme_colors["text"]
|
| 96 |
|
| 97 |
return prs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# https://huggingface.co/spaces/MisterAI/GenDoc_05
|
| 3 |
+
# /home/user/python_pptx/python_pptx.py_01
|
| 4 |
|
| 5 |
from pptx import Presentation
|
| 6 |
from pptx.util import Inches, Pt
|
|
|
|
| 38 |
elif line.startswith("## Titre:"):
|
| 39 |
if current_slide:
|
| 40 |
current_slide['title'] = line[8:].strip()
|
| 41 |
+
elif line.startswith("###"):
|
| 42 |
if current_slide:
|
| 43 |
+
current_slide['points'].append((line[3:].strip(), 'subtitle'))
|
| 44 |
elif line.startswith("- ") and current_slide:
|
| 45 |
if current_slide:
|
| 46 |
+
current_slide['points'].append((line[2:].strip(), 'text'))
|
| 47 |
elif line == "#Fin Slide Ressources Utiles#" or line.startswith("#Fin Slide"):
|
| 48 |
if current_slide:
|
| 49 |
slides.append(current_slide)
|
|
|
|
| 55 |
prs = Presentation()
|
| 56 |
|
| 57 |
# Determine the maximum content slide for font size adjustment
|
| 58 |
+
max_content_length = max(len(" ".join([point[0] for point in slide['points']])) for slide in slides if slide['type'] == 'content')
|
| 59 |
|
| 60 |
# Set font sizes based on the maximum content length
|
| 61 |
base_font_size = 32
|
|
|
|
| 87 |
if slide['points']:
|
| 88 |
body = content_slide.shapes.placeholders[1].text_frame
|
| 89 |
body.clear()
|
| 90 |
+
for point, style in slide['points']:
|
| 91 |
p = body.add_paragraph()
|
| 92 |
+
p.text = self.convert_markdown_links(point)
|
| 93 |
+
p.font.size = Pt(base_font_size if style == 'text' else title_font_size - 4)
|
| 94 |
p.font.name = self.default_font
|
| 95 |
+
p.font.color.rgb = self.default_theme_colors["text" if style == 'text' else 'subtitle']
|
| 96 |
|
| 97 |
return prs
|
| 98 |
+
|
| 99 |
+
def convert_markdown_links(self, text):
|
| 100 |
+
import re
|
| 101 |
+
# Convert Markdown links to hyperlinks
|
| 102 |
+
pattern = r'\[([^\]]+)\]\((https?://[^\)]+)\)'
|
| 103 |
+
repl = r'\1'
|
| 104 |
+
text = re.sub(pattern, repl, text)
|
| 105 |
+
return text
|
| 106 |
+
|
| 107 |
+
def hex_to_rgb(self, hex_color):
|
| 108 |
+
# Convert hex color to RGB tuple
|
| 109 |
+
hex_color = hex_color.lstrip('#')
|
| 110 |
+
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|