Spaces:
Running
Running
Update content_utils.py
Browse files- content_utils.py +35 -8
content_utils.py
CHANGED
|
@@ -1512,6 +1512,24 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1512 |
print(f"[PPTX] Creating file... Theme: {theme_name}")
|
| 1513 |
print(f"[PPTX] Processing {len(results)} slides")
|
| 1514 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1515 |
try:
|
| 1516 |
# Create presentation (16:9 ratio)
|
| 1517 |
prs = Presentation()
|
|
@@ -1532,7 +1550,15 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1532 |
}
|
| 1533 |
|
| 1534 |
if design_themes and theme_name in design_themes:
|
| 1535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1536 |
else:
|
| 1537 |
theme = default_theme
|
| 1538 |
print(f"[PPTX] Using default theme as {theme_name} not found")
|
|
@@ -1681,7 +1707,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1681 |
background = slide.background
|
| 1682 |
fill = background.fill
|
| 1683 |
fill.solid()
|
| 1684 |
-
fill.fore_color.rgb = theme.get("background", RGBColor(250, 250, 252))
|
| 1685 |
|
| 1686 |
# Slide title background box
|
| 1687 |
title_box_bg = slide.shapes.add_shape(
|
|
@@ -1690,7 +1716,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1690 |
Inches(15.4), Inches(1.0)
|
| 1691 |
)
|
| 1692 |
title_box_bg.fill.solid()
|
| 1693 |
-
title_box_bg.fill.fore_color.rgb = theme.get("box_fill", RGBColor(255, 255, 255))
|
| 1694 |
title_box_bg.fill.transparency = 1 - theme.get("box_opacity", 0.95)
|
| 1695 |
|
| 1696 |
# Shadow effect
|
|
@@ -1715,7 +1741,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1715 |
title_para = title_frame.paragraphs[0]
|
| 1716 |
title_para.font.size = Pt(28)
|
| 1717 |
title_para.font.bold = True
|
| 1718 |
-
title_para.font.color.rgb = theme.get("title_color", RGBColor(33, 37, 41))
|
| 1719 |
|
| 1720 |
# Left text area background box
|
| 1721 |
text_box_bg = slide.shapes.add_shape(
|
|
@@ -1724,7 +1750,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1724 |
Inches(7.8), Inches(6.8)
|
| 1725 |
)
|
| 1726 |
text_box_bg.fill.solid()
|
| 1727 |
-
text_box_bg.fill.fore_color.rgb = theme.get("box_fill", RGBColor(255, 255, 255))
|
| 1728 |
text_box_bg.fill.transparency = 1 - theme.get("box_opacity", 0.95)
|
| 1729 |
|
| 1730 |
if theme.get("shadow", True):
|
|
@@ -1751,7 +1777,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1751 |
subtitle_para.text = slide_data.get('subtitle', '')
|
| 1752 |
subtitle_para.font.size = Pt(20)
|
| 1753 |
subtitle_para.font.bold = True
|
| 1754 |
-
subtitle_para.font.color.rgb = theme.get("subtitle_color", RGBColor(52, 58, 64))
|
| 1755 |
subtitle_para.space_after = Pt(20)
|
| 1756 |
|
| 1757 |
# Bullet points
|
|
@@ -1762,7 +1788,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1762 |
clean_text = point.replace('•', '').strip()
|
| 1763 |
p.text = clean_text
|
| 1764 |
p.font.size = Pt(16)
|
| 1765 |
-
p.font.color.rgb = theme.get("text_color", RGBColor(73, 80, 87))
|
| 1766 |
p.level = 0
|
| 1767 |
p.space_after = Pt(12)
|
| 1768 |
p.line_spacing = 1.5
|
|
@@ -1795,7 +1821,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1795 |
page_frame.text = str(i + 1)
|
| 1796 |
page_para = page_frame.paragraphs[0]
|
| 1797 |
page_para.font.size = Pt(12)
|
| 1798 |
-
page_para.font.color.rgb = theme.get("text_color", RGBColor(73, 80, 87))
|
| 1799 |
page_para.alignment = PP_ALIGN.RIGHT
|
| 1800 |
|
| 1801 |
# Add speaker notes
|
|
@@ -1807,6 +1833,7 @@ def create_pptx_file(results: List[Dict], topic: str, template_name: str,
|
|
| 1807 |
|
| 1808 |
# Save file using tempfile for better compatibility
|
| 1809 |
import tempfile
|
|
|
|
| 1810 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 1811 |
filename = f"presentation_{timestamp}.pptx"
|
| 1812 |
|
|
|
|
| 1512 |
print(f"[PPTX] Creating file... Theme: {theme_name}")
|
| 1513 |
print(f"[PPTX] Processing {len(results)} slides")
|
| 1514 |
|
| 1515 |
+
# Helper function to convert color values to RGBColor
|
| 1516 |
+
def get_rgb_color(color_value):
|
| 1517 |
+
"""Convert various color formats to RGBColor"""
|
| 1518 |
+
if isinstance(color_value, RGBColor):
|
| 1519 |
+
return color_value
|
| 1520 |
+
elif isinstance(color_value, tuple) and len(color_value) == 3:
|
| 1521 |
+
return RGBColor(color_value[0], color_value[1], color_value[2])
|
| 1522 |
+
elif isinstance(color_value, str) and color_value.startswith('#'):
|
| 1523 |
+
# Convert hex to RGB
|
| 1524 |
+
hex_color = color_value.lstrip('#')
|
| 1525 |
+
r = int(hex_color[0:2], 16)
|
| 1526 |
+
g = int(hex_color[2:4], 16)
|
| 1527 |
+
b = int(hex_color[4:6], 16)
|
| 1528 |
+
return RGBColor(r, g, b)
|
| 1529 |
+
else:
|
| 1530 |
+
# Default color if conversion fails
|
| 1531 |
+
return RGBColor(128, 128, 128)
|
| 1532 |
+
|
| 1533 |
try:
|
| 1534 |
# Create presentation (16:9 ratio)
|
| 1535 |
prs = Presentation()
|
|
|
|
| 1550 |
}
|
| 1551 |
|
| 1552 |
if design_themes and theme_name in design_themes:
|
| 1553 |
+
raw_theme = design_themes[theme_name]
|
| 1554 |
+
# Convert all color values to RGBColor objects
|
| 1555 |
+
theme = {}
|
| 1556 |
+
for key, value in raw_theme.items():
|
| 1557 |
+
if key in ["background", "title_color", "subtitle_color", "text_color", "accent_color", "box_fill"]:
|
| 1558 |
+
theme[key] = get_rgb_color(value)
|
| 1559 |
+
else:
|
| 1560 |
+
theme[key] = value
|
| 1561 |
+
print(f"[PPTX] Using theme: {theme_name}")
|
| 1562 |
else:
|
| 1563 |
theme = default_theme
|
| 1564 |
print(f"[PPTX] Using default theme as {theme_name} not found")
|
|
|
|
| 1707 |
background = slide.background
|
| 1708 |
fill = background.fill
|
| 1709 |
fill.solid()
|
| 1710 |
+
fill.fore_color.rgb = get_rgb_color(theme.get("background", RGBColor(250, 250, 252)))
|
| 1711 |
|
| 1712 |
# Slide title background box
|
| 1713 |
title_box_bg = slide.shapes.add_shape(
|
|
|
|
| 1716 |
Inches(15.4), Inches(1.0)
|
| 1717 |
)
|
| 1718 |
title_box_bg.fill.solid()
|
| 1719 |
+
title_box_bg.fill.fore_color.rgb = get_rgb_color(theme.get("box_fill", RGBColor(255, 255, 255)))
|
| 1720 |
title_box_bg.fill.transparency = 1 - theme.get("box_opacity", 0.95)
|
| 1721 |
|
| 1722 |
# Shadow effect
|
|
|
|
| 1741 |
title_para = title_frame.paragraphs[0]
|
| 1742 |
title_para.font.size = Pt(28)
|
| 1743 |
title_para.font.bold = True
|
| 1744 |
+
title_para.font.color.rgb = get_rgb_color(theme.get("title_color", RGBColor(33, 37, 41)))
|
| 1745 |
|
| 1746 |
# Left text area background box
|
| 1747 |
text_box_bg = slide.shapes.add_shape(
|
|
|
|
| 1750 |
Inches(7.8), Inches(6.8)
|
| 1751 |
)
|
| 1752 |
text_box_bg.fill.solid()
|
| 1753 |
+
text_box_bg.fill.fore_color.rgb = get_rgb_color(theme.get("box_fill", RGBColor(255, 255, 255)))
|
| 1754 |
text_box_bg.fill.transparency = 1 - theme.get("box_opacity", 0.95)
|
| 1755 |
|
| 1756 |
if theme.get("shadow", True):
|
|
|
|
| 1777 |
subtitle_para.text = slide_data.get('subtitle', '')
|
| 1778 |
subtitle_para.font.size = Pt(20)
|
| 1779 |
subtitle_para.font.bold = True
|
| 1780 |
+
subtitle_para.font.color.rgb = get_rgb_color(theme.get("subtitle_color", RGBColor(52, 58, 64)))
|
| 1781 |
subtitle_para.space_after = Pt(20)
|
| 1782 |
|
| 1783 |
# Bullet points
|
|
|
|
| 1788 |
clean_text = point.replace('•', '').strip()
|
| 1789 |
p.text = clean_text
|
| 1790 |
p.font.size = Pt(16)
|
| 1791 |
+
p.font.color.rgb = get_rgb_color(theme.get("text_color", RGBColor(73, 80, 87)))
|
| 1792 |
p.level = 0
|
| 1793 |
p.space_after = Pt(12)
|
| 1794 |
p.line_spacing = 1.5
|
|
|
|
| 1821 |
page_frame.text = str(i + 1)
|
| 1822 |
page_para = page_frame.paragraphs[0]
|
| 1823 |
page_para.font.size = Pt(12)
|
| 1824 |
+
page_para.font.color.rgb = get_rgb_color(theme.get("text_color", RGBColor(73, 80, 87)))
|
| 1825 |
page_para.alignment = PP_ALIGN.RIGHT
|
| 1826 |
|
| 1827 |
# Add speaker notes
|
|
|
|
| 1833 |
|
| 1834 |
# Save file using tempfile for better compatibility
|
| 1835 |
import tempfile
|
| 1836 |
+
import os
|
| 1837 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 1838 |
filename = f"presentation_{timestamp}.pptx"
|
| 1839 |
|