Spaces:
Runtime error
Runtime error
| from docx import Document | |
| import datetime | |
| import os | |
| def export_docx(questions_text, subject, grade, topic, filename="worksheet.docx"): | |
| doc = Document() | |
| doc.add_heading("🧠 Teacher Buddy Worksheet", 0) | |
| # Metadata | |
| today = datetime.date.today().strftime("%B %d, %Y") | |
| doc.add_paragraph(f"Subject: {subject} Grade: {grade} Topic: {topic}") | |
| doc.add_paragraph(f"Name: ____________________ Date: {today}") | |
| doc.add_paragraph("\n") | |
| # Add questions (no extra numbering) | |
| questions = [q.strip() for q in questions_text.strip().split("\n") if q.strip()] | |
| for q in questions: | |
| doc.add_paragraph(q) | |
| doc.save(filename) | |
| if not os.path.exists(filename): | |
| raise FileNotFoundError(f"{filename} was not created.") | |
| return filename | |