yashm commited on
Commit
92f94a7
·
verified ·
1 Parent(s): 1f4eddf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -45
app.py CHANGED
@@ -1,75 +1,50 @@
1
  import streamlit as st
2
  from pptx import Presentation
3
  from pptx.util import Inches
4
- import os
5
 
6
- # Function to create PowerPoint presentation
7
- def create_presentation():
8
  prs = Presentation()
9
 
10
  # Add a title slide
11
- title_slide_layout = prs.slide_layouts[0] # 0 is for title slide
12
  title_slide = prs.slides.add_slide(title_slide_layout)
13
  title = title_slide.shapes.title
14
  subtitle = title_slide.placeholders[1]
15
- title.text = "Research Presentation Title"
16
  subtitle.text = "Your Name\nYour Institution\nDate"
17
 
18
- # Define the sections with titles and contents
19
- sections = [
20
- {"title": "Introduction", "content": ["Background", "Problem Statement", "Purpose"]},
21
- {"title": "Literature Review", "content": ["Previous Studies", "Key Theories", "Gaps in Research"]},
22
- {"title": "Methodology", "content": ["Research Design", "Data Collection", "Data Analysis"]},
23
- {"title": "Results", "content": ["Data Presentation", "Statistical Analysis", "Interpretation"]},
24
- {"title": "Discussion and Conclusion", "content": ["Summary of Findings", "Implications", "Recommendations for Future Research"]}
25
- ]
26
-
27
- # Loop through each section and create a slide for it
28
- for section in sections:
29
- slide_layout = prs.slide_layouts[1] # 0 is for title slide, 1 for title and content
30
  slide = prs.slides.add_slide(slide_layout)
31
  title_placeholder = slide.shapes.title
32
  body_placeholder = slide.placeholders[1]
33
-
34
- # Set the title and content on the slide
35
- title_placeholder.text = section["title"]
36
  tf = body_placeholder.text_frame
37
- for point in section["content"]:
38
  p = tf.add_paragraph()
39
- p.text = point
40
 
41
- # Add a references slide
42
- references_slide_layout = prs.slide_layouts[1] # Using title and content layout
43
- references_slide = prs.slides.add_slide(references_slide_layout)
44
- references_title = references_slide.shapes.title
45
- references_body = references_slide.placeholders[1]
46
- references_title.text = "References"
47
- references_tf = references_body.text_frame
48
- references = [
49
- "Reference 1: Author Name. (Year). Title. Journal.",
50
- "Reference 2: Author Name. (Year). Title. Journal.",
51
- "Reference 3: Author Name. (Year). Title. Journal."
52
- ] # Modify this list based on your actual references
53
- for ref in references:
54
- p = references_tf.add_paragraph()
55
- p.text = ref
56
-
57
  # Save the presentation
58
- filename = 'detailed_research_presentation.pptx'
59
  prs.save(filename)
60
  return filename
61
 
62
  # Streamlit UI
63
- st.title('PowerPoint Presentation Generator')
64
 
 
 
 
 
 
65
  if st.button('Generate Presentation'):
66
- file_path = create_presentation()
67
  with open(file_path, "rb") as file:
68
  btn = st.download_button(
69
- label="Download PowerPoint Presentation",
70
  data=file,
71
- file_name="research_presentation.pptx",
72
  mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
73
  )
74
-
75
- st.write("Click the button above to generate and download a research presentation PowerPoint.")
 
1
  import streamlit as st
2
  from pptx import Presentation
3
  from pptx.util import Inches
 
4
 
5
+ # Function to create PowerPoint presentation based on user inputs
6
+ def create_presentation(presentation_type, num_sections):
7
  prs = Presentation()
8
 
9
  # Add a title slide
10
+ title_slide_layout = prs.slide_layouts[0]
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 = f"{presentation_type} Title"
15
  subtitle.text = "Your Name\nYour Institution\nDate"
16
 
17
+ # Add specified number of content slides
18
+ for i in range(num_sections):
19
+ slide_layout = prs.slide_layouts[1]
 
 
 
 
 
 
 
 
 
20
  slide = prs.slides.add_slide(slide_layout)
21
  title_placeholder = slide.shapes.title
22
  body_placeholder = slide.placeholders[1]
23
+ title_placeholder.text = f"Section {i+1}"
 
 
24
  tf = body_placeholder.text_frame
25
+ for j in range(5): # Assuming each section will have 5 bullet points
26
  p = tf.add_paragraph()
27
+ p.text = f"Content {j+1}"
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Save the presentation
30
+ filename = f'{presentation_type.lower().replace(" ", "_")}_presentation.pptx'
31
  prs.save(filename)
32
  return filename
33
 
34
  # Streamlit UI
35
+ st.title('Custom Presentation Generator')
36
 
37
+ # User inputs
38
+ presentation_type = st.selectbox('Select Presentation Type', ['Research Presentation', 'Thesis Proposal Presentation', 'Other'])
39
+ num_sections = st.number_input('Number of Sections', min_value=1, max_value=20, value=5)
40
+
41
+ # Generate presentation
42
  if st.button('Generate Presentation'):
43
+ file_path = create_presentation(presentation_type, num_sections)
44
  with open(file_path, "rb") as file:
45
  btn = st.download_button(
46
+ label="Download Presentation",
47
  data=file,
48
+ file_name=file_path,
49
  mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
50
  )