Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from pptx import Presentation
|
|
|
|
| 3 |
|
| 4 |
# Function to create PowerPoint presentation based on user inputs
|
| 5 |
-
def create_presentation(sections):
|
| 6 |
prs = Presentation()
|
| 7 |
|
| 8 |
# Add a title slide
|
|
@@ -10,11 +11,11 @@ def create_presentation(sections):
|
|
| 10 |
title_slide = prs.slides.add_slide(title_slide_layout)
|
| 11 |
title = title_slide.shapes.title
|
| 12 |
subtitle = title_slide.placeholders[1]
|
| 13 |
-
title.text =
|
| 14 |
-
subtitle.text = "
|
| 15 |
|
| 16 |
# Add content slides based on sections
|
| 17 |
-
for section in sections:
|
| 18 |
slide_layout = prs.slide_layouts[1]
|
| 19 |
slide = prs.slides.add_slide(slide_layout)
|
| 20 |
title_placeholder = slide.shapes.title
|
|
@@ -31,22 +32,19 @@ def create_presentation(sections):
|
|
| 31 |
return filename
|
| 32 |
|
| 33 |
# Streamlit UI
|
| 34 |
-
st.title('
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
# Predefined sections based on template type
|
| 40 |
-
if template_type == 'Research Presentation':
|
| 41 |
-
default_sections = [
|
| 42 |
{"title": "Introduction", "content": ["Background", "Problem Statement", "Purpose"]},
|
| 43 |
{"title": "Literature Review", "content": ["Previous Studies", "Key Theories", "Gaps in Research"]},
|
| 44 |
{"title": "Methodology", "content": ["Research Design", "Data Collection", "Data Analysis"]},
|
| 45 |
{"title": "Results", "content": ["Data Presentation", "Statistical Analysis", "Interpretation"]},
|
| 46 |
{"title": "Discussion and Conclusion", "content": ["Summary of Findings", "Implications", "Recommendations for Future Research"]}
|
| 47 |
-
]
|
| 48 |
-
|
| 49 |
-
default_sections = [
|
| 50 |
{"title": "Introduction", "content": ["Background Context", "Problem Statement", "Research Questions", "Purpose and Significance"]},
|
| 51 |
{"title": "Literature Review", "content": ["Key Theories and Concepts", "Current State of Research", "Gaps in Literature"]},
|
| 52 |
{"title": "Research Design and Methodology", "content": ["Research Framework", "Data Collection Methods", "Analysis Plan", "Ethical Considerations"]},
|
|
@@ -56,24 +54,53 @@ elif template_type == 'Proposal Defense':
|
|
| 56 |
{"title": "Conclusion", "content": ["Summary of Key Points", "Reiteration of Research Importance", "Next Steps"]},
|
| 57 |
{"title": "Questions and Discussion", "content": ["Anticipated Questions", "Potential Answers", "Further Clarifications"]}
|
| 58 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.markdown(f"### {default_section['title']}")
|
| 63 |
-
section_title = st.text_input(f"Title", value=default_section['title'], key=f'title_{i}')
|
| 64 |
contents = []
|
| 65 |
-
for j, content in enumerate(
|
| 66 |
-
bullet_point = st.text_area(f"Bullet Point {j+1}", value=content, key=f'section_{i}_bullet_{j}'
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# Generate presentation
|
| 71 |
if st.button('Generate Presentation'):
|
| 72 |
-
file_path = create_presentation(sections)
|
| 73 |
with open(file_path, "rb") as file:
|
| 74 |
-
|
| 75 |
label="Download Presentation",
|
| 76 |
data=file,
|
| 77 |
-
file_name='
|
| 78 |
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
| 79 |
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from pptx import Presentation
|
| 3 |
+
from collections import defaultdict
|
| 4 |
|
| 5 |
# Function to create PowerPoint presentation based on user inputs
|
| 6 |
+
def create_presentation(title_slide_info, sections):
|
| 7 |
prs = Presentation()
|
| 8 |
|
| 9 |
# Add a title slide
|
|
|
|
| 11 |
title_slide = prs.slides.add_slide(title_slide_layout)
|
| 12 |
title = title_slide.shapes.title
|
| 13 |
subtitle = title_slide.placeholders[1]
|
| 14 |
+
title.text = title_slide_info['title']
|
| 15 |
+
subtitle.text = f"{title_slide_info['subtitle']}\n{title_slide_info['institution']}\n{title_slide_info['date']}"
|
| 16 |
|
| 17 |
# Add content slides based on sections
|
| 18 |
+
for section in sections.values():
|
| 19 |
slide_layout = prs.slide_layouts[1]
|
| 20 |
slide = prs.slides.add_slide(slide_layout)
|
| 21 |
title_placeholder = slide.shapes.title
|
|
|
|
| 32 |
return filename
|
| 33 |
|
| 34 |
# Streamlit UI
|
| 35 |
+
st.sidebar.title('Presentation Settings')
|
| 36 |
+
presentation_type = st.sidebar.selectbox('Select Presentation Type', ['Research Presentation', 'Proposal Defense'])
|
| 37 |
|
| 38 |
+
# Template selection
|
| 39 |
+
templates = {
|
| 40 |
+
'Research Presentation': [
|
|
|
|
|
|
|
|
|
|
| 41 |
{"title": "Introduction", "content": ["Background", "Problem Statement", "Purpose"]},
|
| 42 |
{"title": "Literature Review", "content": ["Previous Studies", "Key Theories", "Gaps in Research"]},
|
| 43 |
{"title": "Methodology", "content": ["Research Design", "Data Collection", "Data Analysis"]},
|
| 44 |
{"title": "Results", "content": ["Data Presentation", "Statistical Analysis", "Interpretation"]},
|
| 45 |
{"title": "Discussion and Conclusion", "content": ["Summary of Findings", "Implications", "Recommendations for Future Research"]}
|
| 46 |
+
],
|
| 47 |
+
'Proposal Defense': [
|
|
|
|
| 48 |
{"title": "Introduction", "content": ["Background Context", "Problem Statement", "Research Questions", "Purpose and Significance"]},
|
| 49 |
{"title": "Literature Review", "content": ["Key Theories and Concepts", "Current State of Research", "Gaps in Literature"]},
|
| 50 |
{"title": "Research Design and Methodology", "content": ["Research Framework", "Data Collection Methods", "Analysis Plan", "Ethical Considerations"]},
|
|
|
|
| 54 |
{"title": "Conclusion", "content": ["Summary of Key Points", "Reiteration of Research Importance", "Next Steps"]},
|
| 55 |
{"title": "Questions and Discussion", "content": ["Anticipated Questions", "Potential Answers", "Further Clarifications"]}
|
| 56 |
]
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
default_sections = templates[presentation_type]
|
| 60 |
+
|
| 61 |
+
# Title slide configuration
|
| 62 |
+
st.sidebar.header("Title Slide")
|
| 63 |
+
title = st.sidebar.text_input("Title", "Your Presentation Title")
|
| 64 |
+
subtitle = st.sidebar.text_input("Subtitle", "Your Name")
|
| 65 |
+
institution = st.sidebar.text_input("Institution", "Your Institution")
|
| 66 |
+
presentation_date = st.sidebar.text_input("Date", "Presentation Date")
|
| 67 |
+
title_slide_info = {'title': title, 'subtitle': subtitle, 'institution': institution, 'date': presentation_date}
|
| 68 |
+
|
| 69 |
+
# Sections configuration
|
| 70 |
+
st.title('Customize Your Presentation')
|
| 71 |
+
sections = defaultdict(lambda: {'title': '', 'contents': []}) # Uses defaultdict to handle dynamic section addition
|
| 72 |
+
section_keys = st.session_state.get('section_keys', list(default_sections.keys()))
|
| 73 |
+
new_section_key = st.text_input("Add New Section Title", "")
|
| 74 |
+
|
| 75 |
+
if new_section_key:
|
| 76 |
+
section_keys.append(new_section_key)
|
| 77 |
+
st.session_state['section_keys'] = section_keys # Update session state
|
| 78 |
+
|
| 79 |
+
for i, key in enumerate(section_keys):
|
| 80 |
+
if key in default_sections:
|
| 81 |
+
default_section = default_sections[key]
|
| 82 |
+
section_title = default_section['title']
|
| 83 |
+
default_content = default_section['content']
|
| 84 |
+
else:
|
| 85 |
+
section_title, default_content = key, [""]
|
| 86 |
|
| 87 |
+
st.markdown(f"### {section_title}")
|
| 88 |
+
section_title = st.text_input(f"Title", value=section_title, key=f'title_{i}')
|
|
|
|
|
|
|
| 89 |
contents = []
|
| 90 |
+
for j, content in enumerate(default_content + [""]): # Extra empty string for adding new bullet points
|
| 91 |
+
bullet_point = st.text_area(f"Bullet Point {j+1}", value=content, height=75, key=f'section_{i}_bullet_{j}')
|
| 92 |
+
if bullet_point: # Only add bullet points with content
|
| 93 |
+
contents.append(bullet_point)
|
| 94 |
+
sections[i]['title'] = section_title
|
| 95 |
+
sections[i]['contents'] = contents
|
| 96 |
|
| 97 |
# Generate presentation
|
| 98 |
if st.button('Generate Presentation'):
|
| 99 |
+
file_path = create_presentation(title_slide_info, sections)
|
| 100 |
with open(file_path, "rb") as file:
|
| 101 |
+
st.download_button(
|
| 102 |
label="Download Presentation",
|
| 103 |
data=file,
|
| 104 |
+
file_name='custom_presentation.pptx',
|
| 105 |
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
| 106 |
)
|