initial draft
Browse files
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import networkx as nx
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
# Initialize the lesson plan graph
|
7 |
+
lesson_graph = nx.DiGraph()
|
8 |
+
|
9 |
+
def add_to_graph(teacher_name, subject, grade_level, learning_objective, activity, assessment, resource, school_board):
|
10 |
+
global lesson_graph
|
11 |
+
|
12 |
+
# Add nodes to the graph
|
13 |
+
lesson_graph.add_node(teacher_name, type="User")
|
14 |
+
lesson_graph.add_node(subject, type="Subject")
|
15 |
+
lesson_graph.add_node(grade_level, type="Grade Level")
|
16 |
+
lesson_graph.add_node(learning_objective, type="Learning Objective")
|
17 |
+
lesson_graph.add_node(activity, type="Activity")
|
18 |
+
lesson_graph.add_node(assessment, type="Assessment")
|
19 |
+
lesson_graph.add_node(resource, type="Resource")
|
20 |
+
lesson_graph.add_node(school_board, type="School Board")
|
21 |
+
|
22 |
+
# Add edges to the graph
|
23 |
+
lesson_graph.add_edge(teacher_name, subject, relationship="TEACHES")
|
24 |
+
lesson_graph.add_edge(subject, learning_objective, relationship="COVERS")
|
25 |
+
lesson_graph.add_edge(subject, grade_level, relationship="HAS_GRADE")
|
26 |
+
lesson_graph.add_edge(activity, learning_objective, relationship="ACHIEVES")
|
27 |
+
lesson_graph.add_edge(activity, resource, relationship="REQUIRES")
|
28 |
+
lesson_graph.add_edge(learning_objective, assessment, relationship="EVALUATED_BY")
|
29 |
+
lesson_graph.add_edge(teacher_name, school_board, relationship="BELONGS_TO")
|
30 |
+
lesson_graph.add_edge(learning_objective, school_board, relationship="ALIGNS_WITH")
|
31 |
+
|
32 |
+
# Generate search string
|
33 |
+
search_string = f"{subject} {grade_level} {learning_objective} {activity} {resource}".strip()
|
34 |
+
|
35 |
+
# Visualize the graph
|
36 |
+
plt.figure(figsize=(12, 8))
|
37 |
+
pos = nx.spring_layout(lesson_graph)
|
38 |
+
nx.draw(lesson_graph, pos, with_labels=True, node_color="lightblue",
|
39 |
+
font_size=8, font_weight="bold", node_size=3000, node_shape="o")
|
40 |
+
|
41 |
+
# Add node labels
|
42 |
+
labels = nx.get_node_attributes(lesson_graph, 'type')
|
43 |
+
nx.draw_networkx_labels(lesson_graph, pos, labels, font_size=6)
|
44 |
+
|
45 |
+
# Add edge labels
|
46 |
+
edge_labels = nx.get_edge_attributes(lesson_graph, 'relationship')
|
47 |
+
nx.draw_networkx_edge_labels(lesson_graph, pos, edge_labels=edge_labels, font_size=6)
|
48 |
+
|
49 |
+
# Save the plot to a bytes object
|
50 |
+
buf = BytesIO()
|
51 |
+
plt.savefig(buf, format="png", dpi=300, bbox_inches="tight")
|
52 |
+
buf.seek(0)
|
53 |
+
plt.close()
|
54 |
+
|
55 |
+
return search_string, buf
|
56 |
+
|
57 |
+
def clear_graph():
|
58 |
+
global lesson_graph
|
59 |
+
lesson_graph.clear()
|
60 |
+
return "Canvas cleared. You can start a new lesson plan."
|
61 |
+
|
62 |
+
# Gradio interface
|
63 |
+
demo = gr.Blocks()
|
64 |
+
|
65 |
+
with demo:
|
66 |
+
gr.Markdown("# EduCanvas: Craft Your Lesson Masterpiece")
|
67 |
+
gr.Markdown("Welcome to EduCanvas, where lesson planning becomes an art. Design, visualize, and perfect your educational masterpieces with ease.")
|
68 |
+
|
69 |
+
with gr.Row():
|
70 |
+
teacher_name = gr.Textbox(label="Teacher Name")
|
71 |
+
school_board = gr.Textbox(label="School Board/Region")
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
subject = gr.Textbox(label="Subject")
|
75 |
+
grade_level = gr.Textbox(label="Grade Level")
|
76 |
+
|
77 |
+
with gr.Row():
|
78 |
+
learning_objective = gr.Textbox(label="Learning Objective")
|
79 |
+
activity = gr.Textbox(label="Activity")
|
80 |
+
|
81 |
+
with gr.Row():
|
82 |
+
assessment = gr.Textbox(label="Assessment")
|
83 |
+
resource = gr.Textbox(label="Resource/Material")
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
generate_btn = gr.Button("Paint Your Lesson Plan")
|
87 |
+
clear_btn = gr.Button("Clear Canvas")
|
88 |
+
|
89 |
+
search_output = gr.Textbox(label="Content Discovery Search String")
|
90 |
+
graph_output = gr.Image(label="Your Lesson Masterpiece")
|
91 |
+
message_output = gr.Textbox(label="Canvas Status")
|
92 |
+
|
93 |
+
generate_btn.click(
|
94 |
+
add_to_graph,
|
95 |
+
inputs=[teacher_name, subject, grade_level, learning_objective, activity, assessment, resource, school_board],
|
96 |
+
outputs=[search_output, graph_output]
|
97 |
+
)
|
98 |
+
|
99 |
+
clear_btn.click(clear_graph, outputs=message_output)
|
100 |
+
|
101 |
+
# Launch the EduCanvas app
|
102 |
+
demo.launch()
|