HFUsman commited on
Commit
dd59336
·
verified ·
1 Parent(s): 247a4a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -79
app.py CHANGED
@@ -5,7 +5,7 @@ from io import BytesIO
5
  from PyPDF2 import PdfReader
6
  import docx
7
  from textwrap import wrap
8
- from pptx import Presentation
9
 
10
  # Configure Streamlit
11
  st.set_page_config(
@@ -38,8 +38,7 @@ task = st.sidebar.selectbox("What would you like to do?", [
38
  "Adapt Lesson for Grades",
39
  "Generate Conceptual Assignment",
40
  "Provide Learning Resources",
41
- "Generate Short Conceptual Questions",
42
- "Generate Presentation (PPT)"
43
  ])
44
 
45
  # Helper functions
@@ -71,27 +70,13 @@ def save_to_docx(text, filename="download.docx"):
71
  byte_io.seek(0)
72
  return byte_io
73
 
74
- def save_to_ppt(slides_content, filename="presentation.pptx"):
75
- presentation = Presentation()
76
- for slide_title, slide_content in slides_content:
77
- slide = presentation.slides.add_slide(presentation.slide_layouts[1])
78
- title = slide.shapes.title
79
- body = slide.shapes.placeholders[1]
80
-
81
- title.text = slide_title
82
- tf = body.text_frame
83
- for point in slide_content:
84
- p = tf.add_paragraph()
85
- p.text = point
86
-
87
- byte_io = BytesIO()
88
- presentation.save(byte_io)
89
- byte_io.seek(0)
90
- return byte_io
91
-
92
  # Main App Layout
93
  st.title("EduAI Assistant for Teachers")
94
- st.markdown("""Welcome to your AI-powered teaching assistant!""")
 
 
 
 
95
 
96
  if uploaded_files or manual_input:
97
  lesson_text = ""
@@ -110,63 +95,85 @@ if uploaded_files or manual_input:
110
 
111
  text_chunks = chunk_text(lesson_text)
112
 
113
- if task == "Generate Presentation (PPT)":
114
- topic = st.text_input("Enter the topic for the presentation:")
115
-
116
- if topic:
117
- # Generate slide content based on the topic
118
- slide_content = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  for chunk in text_chunks:
120
- content = process_with_groq([{
121
- "role": "system", "content": "Generate content for a presentation slide."
122
- }, {
123
- "role": "user", "content": f"Topic: {topic}\n\nProvide a few bullet points for a slide on the following content: {chunk}"
124
- }])
125
-
126
- slides = content.split("\n")
127
- title = slides[0] # First line as the slide title
128
- slide_content_points = slides[1:] # Remaining lines as bullet points
129
- slide_content.append((title, slide_content_points))
130
-
131
- # Show the generated slide content for review
132
- st.subheader("Generated Presentation Content")
133
- for i, (slide_title, slide_content_points) in enumerate(slide_content):
134
- st.write(f"### {slide_title}")
135
- for point in slide_content_points:
136
- st.write(f"- {point}")
137
- st.markdown("---")
138
-
139
- # Option to regenerate the content
140
- regenerate = st.button("Regenerate Content")
141
- if regenerate:
142
- st.write("Content regenerated. Review again!")
143
- # Regenerate the content by calling the same process again
144
- slide_content = []
145
- for chunk in text_chunks:
146
- content = process_with_groq([{
147
- "role": "system", "content": "Generate content for a presentation slide."
148
- }, {
149
- "role": "user", "content": f"Topic: {topic}\n\nProvide a few bullet points for a slide on the following content: {chunk}"
150
- }])
151
-
152
- slides = content.split("\n")
153
- title = slides[0] # First line as the slide title
154
- slide_content_points = slides[1:] # Remaining lines as bullet points
155
- slide_content.append((title, slide_content_points))
156
-
157
- # Show regenerated content
158
- st.subheader("Regenerated Presentation Content")
159
- for i, (slide_title, slide_content_points) in enumerate(slide_content):
160
- st.write(f"### {slide_title}")
161
- for point in slide_content_points:
162
- st.write(f"- {point}")
163
- st.markdown("---")
164
-
165
- # Allow download once the user is satisfied
166
- if st.button("Generate PowerPoint"):
167
- ppt_file = save_to_ppt(slide_content)
168
- st.write("### Generated Presentation")
169
- st.download_button("Download Presentation (PPT)", ppt_file, file_name="presentation.pptx")
170
-
 
171
  else:
172
  st.info("Please upload files or enter lesson text to get started.")
 
5
  from PyPDF2 import PdfReader
6
  import docx
7
  from textwrap import wrap
8
+ import json
9
 
10
  # Configure Streamlit
11
  st.set_page_config(
 
38
  "Adapt Lesson for Grades",
39
  "Generate Conceptual Assignment",
40
  "Provide Learning Resources",
41
+ "Generate Conceptual Short Questions"
 
42
  ])
43
 
44
  # Helper functions
 
70
  byte_io.seek(0)
71
  return byte_io
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # Main App Layout
74
  st.title("EduAI Assistant for Teachers")
75
+ st.markdown("""
76
+ Welcome to your AI-powered teaching assistant!
77
+ - Upload lesson files or input text.
78
+ - Perform actions like summarizing topics, generating quizzes, and adapting lessons.
79
+ """)
80
 
81
  if uploaded_files or manual_input:
82
  lesson_text = ""
 
95
 
96
  text_chunks = chunk_text(lesson_text)
97
 
98
+ if task == "Summarize a Topic":
99
+ topic = st.text_input("Enter the topic or keywords:")
100
+ if st.button("Summarize"):
101
+ summaries = [process_with_groq([
102
+ {"role": "system", "content": "Summarize the following lesson content."},
103
+ {"role": "user", "content": f"Context: {chunk}\n\nSummarize the topic: {topic}"}
104
+ ]) for chunk in text_chunks]
105
+ st.write("### Summary")
106
+ summary_text = "\n\n".join(summaries)
107
+ st.write(summary_text)
108
+ docx_file = save_to_docx(summary_text)
109
+ st.download_button("Download Summary as DOCX", docx_file, file_name="summary.docx")
110
+
111
+ elif task == "Ask Questions":
112
+ question = st.text_input("Enter your question:")
113
+ if st.button("Get Answer"):
114
+ answers = [process_with_groq([
115
+ {"role": "system", "content": "You are a helpful teaching assistant."},
116
+ {"role": "user", "content": f"Context: {chunk}\n\nQuestion: {question}"}
117
+ ]) for chunk in text_chunks]
118
+ st.write("### Answer")
119
+ st.write("\n\n".join(answers))
120
+
121
+ elif task == "Generate MCQs":
122
+ num_questions = st.slider("Number of questions to generate:", 1, 10, 5)
123
+ if st.button("Generate MCQs"):
124
+ mcqs = []
125
  for chunk in text_chunks:
126
+ mcqs.extend(process_with_groq([
127
+ {"role": "system", "content": "Generate multiple-choice questions for a lesson."},
128
+ {"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs as a JSON array."}
129
+ ]))
130
+ st.write("### Multiple Choice Questions")
131
+ for mcq in mcqs:
132
+ st.write(f"**{mcq}**")
133
+
134
+ elif task == "Adapt Lesson for Grades":
135
+ grade = st.slider("Select Grade:", 1, 16, 9)
136
+ if st.button("Adapt Lesson"):
137
+ adaptations = [process_with_groq([
138
+ {"role": "system", "content": "Adapt the lesson content for a specific grade."},
139
+ {"role": "user", "content": f"Context: {chunk}\n\nAdapt this lesson for grade {grade}."}
140
+ ]) for chunk in text_chunks]
141
+ st.write("### Adapted Lesson")
142
+ st.write("\n\n".join(adaptations))
143
+
144
+ elif task == "Generate Conceptual Assignment":
145
+ topic = st.text_input("Enter the topic for the assignment:")
146
+ if st.button("Generate Assignment"):
147
+ assignments = [process_with_groq([
148
+ {"role": "system", "content": "Generate a conceptual-based assignment."},
149
+ {"role": "user", "content": f"Context: {chunk}\n\nTopic: {topic}"}
150
+ ]) for chunk in text_chunks]
151
+ st.write("### Conceptual Assignment")
152
+ assignment_text = "\n\n".join(assignments)
153
+ docx_file = save_to_docx(assignment_text)
154
+ st.download_button("Download Assignment as DOCX", docx_file, file_name="assignment.docx")
155
+
156
+ elif task == "Provide Learning Resources":
157
+ topic = st.text_input("Enter the topic:")
158
+ if st.button("Generate Resources"):
159
+ resources = process_with_groq([
160
+ {"role": "system", "content": "Provide a list of learning resources for a topic."},
161
+ {"role": "user", "content": f"Topic: {topic}"}
162
+ ])
163
+ st.write("### Learning Resources")
164
+ st.write(resources)
165
+
166
+ elif task == "Generate Conceptual Short Questions":
167
+ topic = st.text_input("Enter the topic for conceptual short questions:")
168
+ if st.button("Generate Conceptual Short Questions"):
169
+ conceptual_questions = [process_with_groq([
170
+ {"role": "system", "content": "Generate conceptual short questions based on the provided lesson content."},
171
+ {"role": "user", "content": f"Context: {chunk}\n\nGenerate deep conceptual questions for the topic: {topic}"}
172
+ ]) for chunk in text_chunks]
173
+ st.write("### Conceptual Short Questions")
174
+ conceptual_questions_text = "\n\n".join(conceptual_questions)
175
+ st.write(conceptual_questions_text)
176
+ docx_file = save_to_docx(conceptual_questions_text)
177
+ st.download_button("Download Conceptual Short Questions as DOCX", docx_file, file_name="conceptual_short_questions.docx")
178
  else:
179
  st.info("Please upload files or enter lesson text to get started.")