Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import io
|
|
| 5 |
from pydub import AudioSegment
|
| 6 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 7 |
import PyPDF2
|
|
|
|
| 8 |
|
| 9 |
# Set OpenAI API key
|
| 10 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
|
@@ -87,6 +88,37 @@ def generate_section(title, text):
|
|
| 87 |
)
|
| 88 |
return response.choices[0].message.content.strip()
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
# Main app
|
| 91 |
def main():
|
| 92 |
st.set_page_config(layout="wide")
|
|
@@ -154,23 +186,31 @@ def main():
|
|
| 154 |
f"<p>{key_takeaways}</p>" +
|
| 155 |
"</div>", unsafe_allow_html=True)
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
f"<p>{case_studies}</p>" +
|
| 161 |
"</div>", unsafe_allow_html=True)
|
| 162 |
|
| 163 |
st.markdown("### Glossary:")
|
| 164 |
glossary = generate_section("Glossary", summary)
|
| 165 |
-
st.markdown(f"<div style='background-color: black; color: white; padding: 10px; border-radius: 5px;'>"
|
| 166 |
-
f"<p>{glossary}</p>"
|
| 167 |
"</div>", unsafe_allow_html=True)
|
| 168 |
|
| 169 |
st.markdown("### FAQs:")
|
| 170 |
faqs = generate_section("FAQs", summary)
|
| 171 |
-
st.markdown(f"<div style='background-color: black; color: white; padding: 10px; border-radius: 5px;'>"
|
| 172 |
-
f"<p>{faqs}</p>"
|
| 173 |
"</div>", unsafe_allow_html=True)
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
if __name__ == "__main__":
|
| 176 |
main()
|
|
|
|
| 5 |
from pydub import AudioSegment
|
| 6 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 7 |
import PyPDF2
|
| 8 |
+
from pptx import Presentation
|
| 9 |
|
| 10 |
# Set OpenAI API key
|
| 11 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
|
|
|
| 88 |
)
|
| 89 |
return response.choices[0].message.content.strip()
|
| 90 |
|
| 91 |
+
# Function to create PowerPoint presentation
|
| 92 |
+
def create_presentation(summary, key_concepts, key_takeaways, case_studies, glossary, faqs):
|
| 93 |
+
prs = Presentation()
|
| 94 |
+
|
| 95 |
+
# Add title slide
|
| 96 |
+
slide = prs.slides.add_slide(prs.slide_layouts[0])
|
| 97 |
+
title = slide.shapes.title
|
| 98 |
+
subtitle = slide.placeholders[1]
|
| 99 |
+
title.text = "Lecture Notes"
|
| 100 |
+
subtitle.text = "Generated by AI Notes Generation Bot"
|
| 101 |
+
|
| 102 |
+
# Add slides for each section
|
| 103 |
+
def add_slide(title, content):
|
| 104 |
+
slide = prs.slides.add_slide(prs.slide_layouts[1])
|
| 105 |
+
slide.shapes.title.text = title
|
| 106 |
+
textbox = slide.placeholders[1]
|
| 107 |
+
textbox.text = content
|
| 108 |
+
|
| 109 |
+
add_slide("Summary", summary)
|
| 110 |
+
add_slide("Key Concepts", key_concepts)
|
| 111 |
+
add_slide("Key Takeaways", key_takeaways)
|
| 112 |
+
add_slide("Case Studies/Examples", case_studies)
|
| 113 |
+
add_slide("Glossary", glossary)
|
| 114 |
+
add_slide("FAQs", faqs)
|
| 115 |
+
|
| 116 |
+
# Save the presentation to a BytesIO object
|
| 117 |
+
ppt_buffer = io.BytesIO()
|
| 118 |
+
prs.save(ppt_buffer)
|
| 119 |
+
ppt_buffer.seek(0)
|
| 120 |
+
return ppt_buffer
|
| 121 |
+
|
| 122 |
# Main app
|
| 123 |
def main():
|
| 124 |
st.set_page_config(layout="wide")
|
|
|
|
| 186 |
f"<p>{key_takeaways}</p>" +
|
| 187 |
"</div>", unsafe_allow_html=True)
|
| 188 |
|
| 189 |
+
case_studies = generate_section("Case Studies/Examples", summary)
|
| 190 |
+
st.markdown(f"<div style='background-color: black; color: white; padding: 10px; border-radius: 5px;'>"
|
| 191 |
+
f"<p>{case_studies}</p>"
|
|
|
|
| 192 |
"</div>", unsafe_allow_html=True)
|
| 193 |
|
| 194 |
st.markdown("### Glossary:")
|
| 195 |
glossary = generate_section("Glossary", summary)
|
| 196 |
+
st.markdown(f"<div style='background-color: black; color: white; padding: 10px; border-radius: 5px;'>"
|
| 197 |
+
f"<p>{glossary}</p>"
|
| 198 |
"</div>", unsafe_allow_html=True)
|
| 199 |
|
| 200 |
st.markdown("### FAQs:")
|
| 201 |
faqs = generate_section("FAQs", summary)
|
| 202 |
+
st.markdown(f"<div style='background-color: black; color: white; padding: 10px; border-radius: 5px;'>"
|
| 203 |
+
f"<p>{faqs}</p>"
|
| 204 |
"</div>", unsafe_allow_html=True)
|
| 205 |
|
| 206 |
+
# Option to download the PowerPoint presentation
|
| 207 |
+
ppt_buffer = create_presentation(summary, key_concepts, key_takeaways, case_studies, glossary, faqs)
|
| 208 |
+
st.download_button(
|
| 209 |
+
label="Download Presentation",
|
| 210 |
+
data=ppt_buffer,
|
| 211 |
+
file_name="Lecture_Notes_Presentation.pptx",
|
| 212 |
+
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
if __name__ == "__main__":
|
| 216 |
main()
|