Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 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
|
| 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("""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 == "
|
| 114 |
-
topic = st.text_input("Enter the topic
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
for chunk in text_chunks:
|
| 120 |
-
|
| 121 |
-
"role": "system", "content": "Generate
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 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.")
|