HFUsman commited on
Commit
6887739
·
verified ·
1 Parent(s): 4f6e688

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -155,16 +155,18 @@ def provide_learning_resources(topic):
155
  response = client.chat.completions.create(messages=messages, model="llama-3.3-70b-versatile", stream=False)
156
  return response.choices[0].message.content
157
 
158
- # Function to export summary or assignment to DOCX
159
- def export_to_docx(text, filename="download.docx"):
160
  doc = docx.Document()
161
  doc.add_paragraph(text)
162
- doc.save(filename)
163
- return filename
 
 
164
 
165
  # Streamlit app layout
166
  st.title("EduAI Assistant for Teachers")
167
- st.markdown("""
168
  Welcome to the AI-powered teaching assistant!
169
  - Upload your lesson files or input text.
170
  - Ask questions, summarize topics, create quizzes, assignments, and access learning resources.
@@ -208,13 +210,12 @@ if manual_input or uploaded_files:
208
  if st.button("Summarize"):
209
  summaries = [summarize_topic(chunk, topic) for chunk in text_chunks]
210
  st.write("### Summary")
211
- full_summary = "\n\n".join(summaries)
212
- st.write(full_summary)
213
 
214
- # Add export to DOCX button
215
- if st.button("Export Summary to DOCX"):
216
- filename = export_to_docx(full_summary)
217
- st.success(f"Summary has been exported as {filename}")
218
 
219
  elif task == "Ask Questions":
220
  question = st.text_input("Enter your question:")
@@ -248,14 +249,13 @@ if manual_input or uploaded_files:
248
  topic = st.text_input("Enter the topic for assignment generation:")
249
  if st.button("Generate Assignment"):
250
  assignments = [generate_assignment(chunk, topic) for chunk in text_chunks]
 
251
  st.write("### Conceptual Assignment")
252
- full_assignment = "\n\n".join(assignments)
253
- st.write(full_assignment)
254
 
255
- # Add export to DOCX button
256
- if st.button("Export Assignment to DOCX"):
257
- filename = export_to_docx(full_assignment)
258
- st.success(f"Assignment has been exported as {filename}")
259
 
260
  elif task == "Provide Learning Resources":
261
  topic = st.text_input("Enter the topic for learning resources:")
 
155
  response = client.chat.completions.create(messages=messages, model="llama-3.3-70b-versatile", stream=False)
156
  return response.choices[0].message.content
157
 
158
+ # Function to save text to a docx file
159
+ def save_to_docx(text, filename="download.docx"):
160
  doc = docx.Document()
161
  doc.add_paragraph(text)
162
+ byte_io = BytesIO()
163
+ doc.save(byte_io)
164
+ byte_io.seek(0)
165
+ return byte_io
166
 
167
  # Streamlit app layout
168
  st.title("EduAI Assistant for Teachers")
169
+ st.markdown("""
170
  Welcome to the AI-powered teaching assistant!
171
  - Upload your lesson files or input text.
172
  - Ask questions, summarize topics, create quizzes, assignments, and access learning resources.
 
210
  if st.button("Summarize"):
211
  summaries = [summarize_topic(chunk, topic) for chunk in text_chunks]
212
  st.write("### Summary")
213
+ summary_text = "\n\n".join(summaries)
214
+ st.write(summary_text)
215
 
216
+ # Export to docx
217
+ docx_file = save_to_docx(summary_text)
218
+ st.download_button("Download Summary as DOCX", docx_file, file_name="summary.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
 
219
 
220
  elif task == "Ask Questions":
221
  question = st.text_input("Enter your question:")
 
249
  topic = st.text_input("Enter the topic for assignment generation:")
250
  if st.button("Generate Assignment"):
251
  assignments = [generate_assignment(chunk, topic) for chunk in text_chunks]
252
+ assignment_text = "\n\n".join(assignments)
253
  st.write("### Conceptual Assignment")
254
+ st.write(assignment_text)
 
255
 
256
+ # Export to docx
257
+ docx_file = save_to_docx(assignment_text)
258
+ st.download_button("Download Assignment as DOCX", docx_file, file_name="assignment.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
 
259
 
260
  elif task == "Provide Learning Resources":
261
  topic = st.text_input("Enter the topic for learning resources:")