donb-hf commited on
Commit
6f03cc8
Β·
verified Β·
1 Parent(s): 2e33552

update buttons

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -99,6 +99,39 @@ def clear_graph():
99
  lesson_graph.clear()
100
  return "Landscape cleared. You can start a new lesson plan."
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  # Gradio interface
103
  demo = gr.Blocks()
104
 
@@ -143,6 +176,14 @@ with demo:
143
  inputs=[teacher_name, subject, grade_level, learning_objective, activity, assessment, resource, school_board],
144
  outputs=[search_output, graph_output]
145
  )
 
 
 
 
 
 
 
 
146
 
147
  clear_btn.click(clear_graph, outputs=message_output)
148
 
 
99
  lesson_graph.clear()
100
  return "Landscape cleared. You can start a new lesson plan."
101
 
102
+ import json
103
+
104
+ def graph_to_json():
105
+ # Convert the lesson_graph to a dictionary format
106
+ graph_data = {
107
+ "nodes": [
108
+ {
109
+ "id": node,
110
+ "type": lesson_graph.nodes[node]["type"],
111
+ "description": lesson_graph.nodes[node].get("description", "")
112
+ }
113
+ for node in lesson_graph.nodes()
114
+ ],
115
+ "edges": [
116
+ {
117
+ "source": u,
118
+ "target": v,
119
+ "relationship": lesson_graph.edges[u, v]["relationship"]
120
+ }
121
+ for u, v in lesson_graph.edges()
122
+ ]
123
+ }
124
+
125
+ # Convert dictionary to JSON string
126
+ json_data = json.dumps(graph_data, indent=4)
127
+
128
+ # Save to a file
129
+ file_name = "/mnt/data/lesson_graph.json"
130
+ with open(file_name, "w") as f:
131
+ f.write(json_data)
132
+
133
+ return file_name
134
+
135
  # Gradio interface
136
  demo = gr.Blocks()
137
 
 
176
  inputs=[teacher_name, subject, grade_level, learning_objective, activity, assessment, resource, school_board],
177
  outputs=[search_output, graph_output]
178
  )
179
+
180
+ # Adding the button to download the lesson graph as JSON
181
+ download_btn = gr.Button("Download Lesson Graph (JSON)")
182
+
183
+ download_btn.click(
184
+ graph_to_json,
185
+ outputs=gr.File(label="Download JSON File")
186
+ )
187
 
188
  clear_btn.click(clear_graph, outputs=message_output)
189