kshitij10000 commited on
Commit
d7e28c8
·
1 Parent(s): 6ede971

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -138
app.py DELETED
@@ -1,138 +0,0 @@
1
- import openai
2
- import json
3
- from pptx import Presentation
4
- import streamlit as st
5
- import os
6
-
7
- # Suppress all warnings
8
- import warnings
9
- warnings.filterwarnings("ignore")
10
-
11
- # Set your OpenAI API key
12
- openai.api_key = "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"
13
-
14
- # Streamlit app layout with custom styling
15
- st.title("🚀 PowerPoint Presentation Generator")
16
-
17
- # Add stars in the background
18
- st.markdown(
19
- """
20
- <style>
21
- body {
22
- background: url('https://image.freepik.com/free-vector/dark-blue-abstract-night-sky-background-with-stars_1017-26660.jpg');
23
- background-size: cover;
24
- font-family: Arial, sans-serif;
25
- color: white !important;
26
- }
27
- </style>
28
- """,
29
- unsafe_allow_html=True
30
- )
31
-
32
- # Content section with black text color
33
- st.write(
34
- """
35
- **Welcome to the PowerPoint Presentation Generator!** ✨
36
-
37
- Have you ever wished creating presentations could be easier and more fun? Look no further! With our AI-powered model, you can quickly generate presentation content, and the design will be your part. 🎨
38
-
39
- **What we do:**
40
- - You provide the presentation topic, and we add engaging content.
41
- - Our model ensures each slide has the right balance of information.
42
- - We make presentations a breeze, and we have exciting features coming in the future. 🚀
43
-
44
- **Limits (for now, subject to change in future updates):**
45
- - You can create a maximum of 20 slides per presentation.
46
- - Each slide should have between 3 and 10 points of content.
47
- - Maximum 10 slides, minimum 3 points, maximum 10 points.
48
-
49
- ⚠️ **Important Notice:** Occasionally, when downloading the file multiple times, it may display the PowerPoint content in a vertical format. If you encounter this issue, please try downloading the file again by deleting the previous one or adjusting your input parameters. We apologize for any inconvenience and are here to assist you.
50
-
51
- If you encounter any questions, problems, or have cool ideas for future enhancements, don't hesitate to contact us. Your feedback is valuable, and we're here to make your experience the best it can be! 🌟
52
- """,
53
- unsafe_allow_html=True
54
- )
55
-
56
- # Input for presentation topic
57
- presentation_title = st.text_input("Enter your presentation topic:")
58
- no_of_pages = st.number_input("Number of slides you want", min_value=1, max_value=10, value=1) # Update max_value
59
- least_c = st.number_input("Minimum points in each slide", min_value=3, value=3) # Remove max_value
60
- max_c = st.number_input("Maximum points in each slide", min_value=3, value=10) # Remove max_value
61
-
62
- if st.button("Generate Presentation"):
63
- # Check if the user has entered a topic
64
- if presentation_title:
65
- question = (
66
- f"generate a {no_of_pages} slide presentation for the topic {presentation_title}."
67
- f" Each slide should have {{header}}, {{content}}, should have at least {least_c} points and max {max_c} points in content. Return as JSON"
68
- )
69
-
70
- query_json = {
71
- "input_text": question,
72
- "output_format": "json",
73
- "max_tokens": 150,
74
- }
75
-
76
- # Send the query to OpenAI
77
- completion = openai.Completion.create(
78
- engine="davinci",
79
- prompt=json.dumps(query_json),
80
- max_tokens=150,
81
- )
82
-
83
- try:
84
- response = json.loads(completion.choices[0].text)
85
-
86
- if "slides" in response:
87
- slide_data = response["slides"]
88
- else:
89
- st.error("No slides found in the response. Please try again.")
90
- st.stop()
91
-
92
- prs = Presentation()
93
-
94
- from pptx.util import Pt
95
- from pptx.enum.text import PP_ALIGN
96
-
97
- # Iterate through slide data and populate the presentation
98
- for slide in slide_data:
99
- slide_layout = prs.slide_layouts[1]
100
- new_slide = prs.slides.add_slide(slide_layout)
101
-
102
- if "header" in slide:
103
- title = new_slide.shapes.title
104
- title.text = slide["header"]
105
-
106
- if "content" in slide:
107
- shapes = new_slide.shapes
108
- body_shape = shapes.placeholders[1]
109
- tf = body_shape.text_frame
110
-
111
- # Join the list of content into a single string with line breaks
112
- content_text = "\n".join(slide["content"])
113
-
114
- p = tf.add_paragraph()
115
- p.text = content_text
116
- p.space_after = Pt(14)
117
- p.alignment = PP_ALIGN.LEFT
118
-
119
- # Save the presentation in PPTX format with the topic name as the file name
120
- presentation_filename = f"{presentation_title}.pptx"
121
- prs.save(presentation_filename)
122
-
123
- # Provide a direct download link with a custom filename
124
- with open(presentation_filename, "rb") as file:
125
- # Specify the custom filename using the "key" parameter
126
- st.download_button(
127
- label=f"Download {presentation_title}.pptx", # Add .pptx extension to the label
128
- data=file.read(),
129
- key=presentation_filename,
130
- file_name=presentation_filename
131
- )
132
-
133
- # Delete the temporary presentation file
134
- os.remove(presentation_filename)
135
- except json.JSONDecodeError as e:
136
- st.error("Error parsing JSON response from OpenAI.")
137
- else:
138
- st.warning("Please enter a presentation topic.")