update app
Browse files
app.py
CHANGED
|
@@ -3,13 +3,29 @@ import networkx as nx
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from io import BytesIO
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
|
| 7 |
# Initialize the lesson plan graph
|
| 8 |
lesson_graph = nx.DiGraph()
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def add_to_graph(teacher_name, subject, grade_level, learning_objective, activity, assessment, resource, school_board):
|
| 11 |
global lesson_graph
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
# Add nodes to the graph
|
| 14 |
lesson_graph.add_node(teacher_name, type="User")
|
| 15 |
lesson_graph.add_node(subject, type="Subject")
|
|
@@ -34,18 +50,28 @@ def add_to_graph(teacher_name, subject, grade_level, learning_objective, activit
|
|
| 34 |
search_string = f"{subject} {grade_level} {learning_objective} {activity} {resource}".strip()
|
| 35 |
|
| 36 |
# Visualize the graph
|
| 37 |
-
plt.figure(figsize=(
|
| 38 |
-
pos = nx.spring_layout(lesson_graph)
|
| 39 |
-
nx.draw(lesson_graph, pos, with_labels=True, node_color="lightblue",
|
| 40 |
-
font_size=8, font_weight="bold", node_size=3000, node_shape="o")
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Add edge labels
|
| 47 |
edge_labels = nx.get_edge_attributes(lesson_graph, 'relationship')
|
| 48 |
-
nx.draw_networkx_edge_labels(lesson_graph, pos, edge_labels=edge_labels, font_size=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Save the plot to a bytes object
|
| 51 |
buf = BytesIO()
|
|
@@ -61,14 +87,14 @@ def add_to_graph(teacher_name, subject, grade_level, learning_objective, activit
|
|
| 61 |
def clear_graph():
|
| 62 |
global lesson_graph
|
| 63 |
lesson_graph.clear()
|
| 64 |
-
return "
|
| 65 |
|
| 66 |
# Gradio interface
|
| 67 |
demo = gr.Blocks()
|
| 68 |
|
| 69 |
with demo:
|
| 70 |
-
gr.Markdown("#
|
| 71 |
-
gr.Markdown("Welcome to
|
| 72 |
|
| 73 |
with gr.Row():
|
| 74 |
teacher_name = gr.Textbox(label="Teacher Name")
|
|
@@ -87,12 +113,12 @@ with demo:
|
|
| 87 |
resource = gr.Textbox(label="Resource/Material")
|
| 88 |
|
| 89 |
with gr.Row():
|
| 90 |
-
generate_btn = gr.Button("
|
| 91 |
-
clear_btn = gr.Button("Clear
|
| 92 |
|
| 93 |
search_output = gr.Textbox(label="Content Discovery Search String")
|
| 94 |
-
graph_output = gr.Image(label="Your
|
| 95 |
-
message_output = gr.Textbox(label="
|
| 96 |
|
| 97 |
generate_btn.click(
|
| 98 |
add_to_graph,
|
|
@@ -102,5 +128,5 @@ with demo:
|
|
| 102 |
|
| 103 |
clear_btn.click(clear_graph, outputs=message_output)
|
| 104 |
|
| 105 |
-
# Launch the
|
| 106 |
demo.launch()
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from io import BytesIO
|
| 5 |
from PIL import Image
|
| 6 |
+
import matplotlib.patches as mpatches
|
| 7 |
|
| 8 |
# Initialize the lesson plan graph
|
| 9 |
lesson_graph = nx.DiGraph()
|
| 10 |
|
| 11 |
+
# Define color map for node types
|
| 12 |
+
color_map = {
|
| 13 |
+
"User": "#FF9999", # Light Red
|
| 14 |
+
"Subject": "#66B2FF", # Light Blue
|
| 15 |
+
"Grade Level": "#99FF99", # Light Green
|
| 16 |
+
"Learning Objective": "#FFCC99", # Light Orange
|
| 17 |
+
"Activity": "#FF99FF", # Light Purple
|
| 18 |
+
"Assessment": "#FFFF99", # Light Yellow
|
| 19 |
+
"Resource": "#99FFFF", # Light Cyan
|
| 20 |
+
"School Board": "#CCCCCC" # Light Gray
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
def add_to_graph(teacher_name, subject, grade_level, learning_objective, activity, assessment, resource, school_board):
|
| 24 |
global lesson_graph
|
| 25 |
|
| 26 |
+
# Clear previous graph
|
| 27 |
+
lesson_graph.clear()
|
| 28 |
+
|
| 29 |
# Add nodes to the graph
|
| 30 |
lesson_graph.add_node(teacher_name, type="User")
|
| 31 |
lesson_graph.add_node(subject, type="Subject")
|
|
|
|
| 50 |
search_string = f"{subject} {grade_level} {learning_objective} {activity} {resource}".strip()
|
| 51 |
|
| 52 |
# Visualize the graph
|
| 53 |
+
plt.figure(figsize=(14, 10))
|
| 54 |
+
pos = nx.spring_layout(lesson_graph, k=0.9, iterations=50)
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
# Draw nodes with color coding
|
| 57 |
+
for node, node_type in nx.get_node_attributes(lesson_graph, 'type').items():
|
| 58 |
+
nx.draw_networkx_nodes(lesson_graph, pos, nodelist=[node], node_color=color_map[node_type],
|
| 59 |
+
node_size=3000, alpha=0.8)
|
| 60 |
+
|
| 61 |
+
nx.draw_networkx_edges(lesson_graph, pos, edge_color='gray', arrows=True, arrowsize=20)
|
| 62 |
+
nx.draw_networkx_labels(lesson_graph, pos, font_size=8, font_weight="bold")
|
| 63 |
|
| 64 |
# Add edge labels
|
| 65 |
edge_labels = nx.get_edge_attributes(lesson_graph, 'relationship')
|
| 66 |
+
nx.draw_networkx_edge_labels(lesson_graph, pos, edge_labels=edge_labels, font_size=7)
|
| 67 |
+
|
| 68 |
+
# Create legend
|
| 69 |
+
legend_elements = [mpatches.Patch(color=color, label=node_type) for node_type, color in color_map.items()]
|
| 70 |
+
plt.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(1, 1), title="Node Types")
|
| 71 |
+
|
| 72 |
+
plt.title("Your Educational Landscape", fontsize=16)
|
| 73 |
+
plt.axis('off')
|
| 74 |
+
plt.tight_layout()
|
| 75 |
|
| 76 |
# Save the plot to a bytes object
|
| 77 |
buf = BytesIO()
|
|
|
|
| 87 |
def clear_graph():
|
| 88 |
global lesson_graph
|
| 89 |
lesson_graph.clear()
|
| 90 |
+
return "Landscape cleared. You can start a new lesson plan."
|
| 91 |
|
| 92 |
# Gradio interface
|
| 93 |
demo = gr.Blocks()
|
| 94 |
|
| 95 |
with demo:
|
| 96 |
+
gr.Markdown("# EduScape: Design Your Educational Landscape")
|
| 97 |
+
gr.Markdown("Welcome to EduScape, where lesson planning becomes an adventure in crafting educational journeys. Design, visualize, and perfect your learning landscapes with ease.")
|
| 98 |
|
| 99 |
with gr.Row():
|
| 100 |
teacher_name = gr.Textbox(label="Teacher Name")
|
|
|
|
| 113 |
resource = gr.Textbox(label="Resource/Material")
|
| 114 |
|
| 115 |
with gr.Row():
|
| 116 |
+
generate_btn = gr.Button("Map Your Lesson Plan")
|
| 117 |
+
clear_btn = gr.Button("Clear Landscape")
|
| 118 |
|
| 119 |
search_output = gr.Textbox(label="Content Discovery Search String")
|
| 120 |
+
graph_output = gr.Image(label="Your Educational Landscape")
|
| 121 |
+
message_output = gr.Textbox(label="Landscape Status")
|
| 122 |
|
| 123 |
generate_btn.click(
|
| 124 |
add_to_graph,
|
|
|
|
| 128 |
|
| 129 |
clear_btn.click(clear_graph, outputs=message_output)
|
| 130 |
|
| 131 |
+
# Launch the EduScape app
|
| 132 |
demo.launch()
|