Spaces:
Sleeping
Sleeping
File size: 10,775 Bytes
1f4eddf ca039d5 ad30388 ca039d5 1f4eddf ad30388 091bb45 c33529b 091bb45 ca039d5 92f94a7 50543ae 1f4eddf ca039d5 1f4eddf 92f94a7 1f4eddf 7dbdbe2 1f4eddf ad30388 45bba28 35622fd 50543ae 35622fd 1f4eddf a1468a3 1f4eddf ca039d5 35622fd ca039d5 c33529b ad30388 7dbdbe2 c33529b 13a6efb 1f4eddf 0f008f8 7dbdbe2 ca039d5 3ed37d1 2ca4411 c33529b 3ed37d1 50543ae 633f6cc 3ed37d1 633f6cc 3ed37d1 50543ae 633f6cc c33529b 2ca4411 50543ae ca039d5 50543ae ca039d5 091bb45 1f4eddf 50543ae 1f4eddf 7dbdbe2 ad30388 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
import streamlit as st
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
from collections import OrderedDict
import os
# Define templates for different presentation types
templates = {
'Research Presentation': [
{"title": "Introduction", "content": ["Background", "Problem Statement", "Purpose"]},
{"title": "Literature Review", "content": ["Previous Studies", "Key Theories", "Gaps in Research"]},
{"title": "Methodology", "content": ["Research Design", "Data Collection", "Data Analysis"]},
{"title": "Results", "content": ["Data Presentation", "Statistical Analysis", "Interpretation"]},
{"title": "Discussion and Conclusion", "content": ["Summary of Findings", "Implications", "Recommendations for Future Research"]}
],
'Proposal Defense': [
{"title": "Introduction", "content": ["Background Context", "Problem Statement", "Research Questions", "Purpose and Significance"]},
{"title": "Literature Review", "content": ["Key Theories and Concepts", "Current State of Research", "Gaps in Literature"]},
{"title": "Research Design and Methodology", "content": ["Research Framework", "Data Collection Methods", "Analysis Plan", "Ethical Considerations"]},
{"title": "Expected Results", "content": ["Predicted Outcomes", "Potential Implications", "Limitations"]},
{"title": "Timeline", "content": ["Research Phases", "Key Milestones", "Completion Dates"]},
{"title": "Budget", "content": ["Estimated Costs", "Resource Allocation", "Justification"]},
{"title": "Conclusion", "content": ["Summary of Key Points", "Reiteration of Research Importance", "Next Steps"]},
{"title": "Questions and Discussion", "content": ["Anticipated Questions", "Potential Answers", "Further Clarifications"]}
],
'Project Update': [
{"title": "Overview", "content": ["Project Background", "Current Status", "Objectives"]},
{"title": "Progress", "content": ["Tasks Completed", "Milestones Achieved", "Challenges Faced"]},
{"title": "Next Steps", "content": ["Upcoming Tasks", "Milestones", "Deadlines"]},
{"title": "Risks and Issues", "content": ["Current Risks", "Mitigation Strategies", "Dependencies"]},
{"title": "Summary", "content": ["Key Takeaways", "Action Items", "Follow-up Dates"]}
],
'Thesis Defense': [
{"title": "Introduction", "content": ["Research Topic", "Research Questions", "Hypotheses"]},
{"title": "Methodology", "content": ["Research Design", "Data Collection Methods", "Data Analysis Procedures"]},
{"title": "Results", "content": ["Key Findings", "Data Interpretation", "Implications"]},
{"title": "Conclusion", "content": ["Summary of Findings", "Research Contributions", "Future Research"]},
{"title": "Questions and Discussion", "content": ["Common Questions", "Clarifications", "Further Explanations"]}
],
'Business Pitch': [
{"title": "Company Overview", "content": ["Company Background", "Mission and Vision", "Team"]},
{"title": "Market Analysis", "content": ["Industry Overview", "Target Market", "Competitor Analysis"]},
{"title": "Product/Service", "content": ["Product Description", "Unique Selling Points", "Value Proposition"]},
{"title": "Business Model", "content": ["Revenue Streams", "Pricing Strategy", "Sales Channels"]},
{"title": "Financial Plan", "content": ["Revenue Projections", "Cost Structure", "Funding Requirements"]},
{"title": "Conclusion", "content": ["Summary", "Call to Action", "Contact Information"]}
]
}
# Define themes
themes = {
"Corporate": {"font": "Arial", "font_size": 20, "color": "0000FF"},
"Casual": {"font": "Comic Sans MS", "font_size": 18, "color": "FF5733"},
# Add more themes as needed
}
# Function to create PowerPoint presentation based on user inputs
def create_presentation(title_slide_info, sections, theme_name, image_sections):
prs = Presentation()
# Apply theme
theme = themes[theme_name]
# Add a title slide
title_slide_layout = prs.slide_layouts[0]
title_slide = prs.slides.add_slide(title_slide_layout)
title = title_slide.shapes.title
subtitle = title_slide.placeholders[1]
title.text = title_slide_info['title']
subtitle.text = f"{title_slide_info['subtitle']}\n{title_slide_info['institution']}\n{title_slide_info['date']}"
# Add content slides based on sections and subsections
for section_title, section_info in sections.items():
for subsection_title, bullet_points in section_info.items():
slide = add_slide_with_layout(prs, 1, f"{section_title} - {subsection_title}", bullet_points)
# Check if this is the subsection where the image should be added
if section_title in image_sections and image_sections[section_title] == subsection_title:
image_path = os.path.join(os.getcwd(), uploaded_images[section_title].name)
with open(image_path, "wb") as f:
f.write(uploaded_images[section_title].getbuffer())
add_image_to_slide(slide, image_path)
# Save the presentation
filename = 'custom_presentation.pptx'
prs.save(filename)
return filename
# Function to style text
def style_text(paragraph, font_size, font_color):
run = paragraph.add_run()
font = run.font
font.size = Pt(font_size)
font.color.rgb = RGBColor.from_string(font_color)
# Function to add slide with custom layout
def add_slide_with_layout(prs, layout_index, title_text, content_points):
slide_layout = prs.slide_layouts[layout_index]
slide = prs.slides.add_slide(slide_layout)
title_placeholder = slide.shapes.title
body_placeholder = slide.placeholders[1]
title_placeholder.text = title_text
for point in content_points:
p = body_placeholder.text_frame.add_paragraph()
p.text = point
return slide
# Function to add image to a slide
def add_image_to_slide(slide, image_path):
slide.shapes.add_picture(image_path, Inches(1), Inches(1), width=Inches(5), height=Inches(3))
# Function to handle dynamic section addition
def add_new_section(section_counter):
new_section_title = f"Section {section_counter}"
st.session_state.sections[new_section_title] = OrderedDict({"Subsection": []})
st.session_state.section_counter += 1
# Function to handle dynamic subsection addition
def add_new_subsection(section_title):
new_subsection_title = f"Subsection {len(st.session_state.sections[section_title]) + 1}"
if new_subsection_title not in st.session_state.sections[section_title]:
st.session_state.sections[section_title][new_subsection_title] = []
# Streamlit UI setup
st.sidebar.title('Presentation Settings')
presentation_type = st.sidebar.selectbox('Select Presentation Type', list(templates.keys()))
# Reset sections when a new presentation type is selected
if 'last_presentation_type' not in st.session_state or st.session_state.last_presentation_type != presentation_type:
st.session_state.sections = OrderedDict()
st.session_state.section_counter = 1 # Counter for unique section names
for section in templates[presentation_type]:
st.session_state.sections[section['title']] = OrderedDict((content, []) for content in section['content'])
st.session_state.last_presentation_type = presentation_type # Update the last selected type
# Title slide configuration with expander
with st.sidebar.expander("Title Slide Options", expanded=False):
title_slide_info = {
'title': st.text_input("Title", "Your Presentation Title"),
'subtitle': st.text_input("Subtitle", "Your Name"),
'institution': st.text_input("Institution", "Your Institution"),
'date': st.text_input("Date", "Presentation Date")
}
# Theme selection
theme_name = st.sidebar.selectbox("Select Theme", list(themes.keys()))
# Option to add more sections dynamically
if st.sidebar.button("Add More Section"):
add_new_section(st.session_state.section_counter)
# Main page for sections and subsections configuration
st.title('Customize Your Presentation')
# Dictionary to keep track of which section/subsection should have an image
image_sections = {}
for section_title, subsections in list(st.session_state.sections.items()):
with st.expander(f"Section: {section_title}"):
# Edit section title
new_section_title = st.text_input(f"Edit Section Title:", value=section_title, key=f"section_title_{section_title}")
if new_section_title != section_title:
st.session_state.sections[new_section_title] = st.session_state.sections.pop(section_title)
section_title = new_section_title
for subsection_title, bullet_points in list(subsections.items()):
bullets = st.text_area(f"Subsection: {subsection_title} (Enter bullet points separated by newlines)",
value="\n".join(bullet_points),
height=150,
key=f"{section_title}_{subsection_title}").split('\n')
st.session_state.sections[section_title][subsection_title] = bullets
# Let the user choose if this is the subsection where the image should be added
add_image_here = st.checkbox(f"Add image to {subsection_title}?", key=f"checkbox_{section_title}_{subsection_title}")
if add_image_here:
image_sections[section_title] = subsection_title
# Add new subsection to the current section
if st.button(f"Add Subsection to {section_title}", key=f"add_subsection_{section_title}"):
add_new_subsection(section_title)
# Image upload for each section (images should only be uploaded if selected)
uploaded_images = {}
for section_title in st.session_state.sections:
if section_title in image_sections:
uploaded_image = st.file_uploader(f"Upload image for {section_title} (applied to subsection '{image_sections[section_title]}')", type=["png", "jpg", "jpeg"], key=f"image_{section_title}")
if uploaded_image is not None:
uploaded_images[section_title] = uploaded_image
# Generate and download presentation
if st.button('Generate Presentation'):
file_path = create_presentation(title_slide_info, st.session_state.sections, theme_name, image_sections)
with open(file_path, "rb") as file:
st.download_button(
label="Download Presentation",
data=file,
file_name='custom_presentation.pptx',
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
)
|