kwabs22 commited on
Commit
a4229ac
·
1 Parent(s): 8b6d6cd

Fixing save all in config editor

Browse files
Files changed (1) hide show
  1. app.py +52 -9
app.py CHANGED
@@ -159,6 +159,50 @@ def show_elements(text):
159
 
160
  return outputs
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  def show_elements_json_input(json_input):
163
  data = json.loads(json_input)
164
  masterlocation1 = data['masterlocation1']
@@ -182,16 +226,15 @@ def show_elements_json_input(json_input):
182
  transitions = gr.Textbox(label="Transitions", value=json.dumps(details['transitions']), interactive=True)
183
  outputs.append(transitions)
184
 
185
- def update_json():
186
  updated_data = {"masterlocation1": {}}
187
- for i, location in enumerate(masterlocation1.keys()):
188
- if location == 'end':
189
- continue
190
  updated_data["masterlocation1"][location] = {
191
- "description": outputs[i*4].value,
192
- "events": json.loads(outputs[i*4 + 1].value),
193
- "choices": json.loads(outputs[i*4 + 2].value),
194
- "transitions": json.loads(outputs[i*4 + 3].value)
195
  }
196
  updated_data["masterlocation1"]["end"] = masterlocation1["end"]
197
  return json.dumps(updated_data, indent=2)
@@ -199,7 +242,7 @@ def show_elements_json_input(json_input):
199
  update_button = gr.Button("Update JSON")
200
  json_output = gr.Textbox(label="Updated JSON", lines=10)
201
 
202
- update_button.click(update_json, outputs=json_output)
203
 
204
  return outputs + [update_button, json_output]
205
 
 
159
 
160
  return outputs
161
 
162
+ # def show_elements_json_input(json_input):
163
+ # data = json.loads(json_input)
164
+ # masterlocation1 = data['masterlocation1']
165
+
166
+ # outputs = []
167
+
168
+ # for location, details in masterlocation1.items():
169
+ # if location == 'end':
170
+ # continue
171
+
172
+ # with gr.Accordion(f"Location: {location}"):
173
+ # description = gr.Textbox(label="Description", value=details['description'], interactive=True)
174
+ # outputs.append(description)
175
+
176
+ # events = gr.Textbox(label="Events", value=json.dumps(details['events']), interactive=True)
177
+ # outputs.append(events)
178
+
179
+ # choices = gr.Textbox(label="Choices", value=json.dumps(details['choices']), interactive=True)
180
+ # outputs.append(choices)
181
+
182
+ # transitions = gr.Textbox(label="Transitions", value=json.dumps(details['transitions']), interactive=True)
183
+ # outputs.append(transitions)
184
+
185
+ # def update_json():
186
+ # updated_data = {"masterlocation1": {}}
187
+ # for i, location in enumerate(masterlocation1.keys()):
188
+ # if location == 'end':
189
+ # continue
190
+ # updated_data["masterlocation1"][location] = {
191
+ # "description": outputs[i*4].value,
192
+ # "events": json.loads(outputs[i*4 + 1].value),
193
+ # "choices": json.loads(outputs[i*4 + 2].value),
194
+ # "transitions": json.loads(outputs[i*4 + 3].value)
195
+ # }
196
+ # updated_data["masterlocation1"]["end"] = masterlocation1["end"]
197
+ # return json.dumps(updated_data, indent=2)
198
+
199
+ # update_button = gr.Button("Update JSON")
200
+ # json_output = gr.Textbox(label="Updated JSON", lines=10)
201
+
202
+ # update_button.click(update_json, outputs=json_output)
203
+
204
+ # return outputs + [update_button, json_output]
205
+
206
  def show_elements_json_input(json_input):
207
  data = json.loads(json_input)
208
  masterlocation1 = data['masterlocation1']
 
226
  transitions = gr.Textbox(label="Transitions", value=json.dumps(details['transitions']), interactive=True)
227
  outputs.append(transitions)
228
 
229
+ def update_json(*current_values):
230
  updated_data = {"masterlocation1": {}}
231
+ locations = [loc for loc in masterlocation1.keys() if loc != 'end']
232
+ for i, location in enumerate(locations):
 
233
  updated_data["masterlocation1"][location] = {
234
+ "description": current_values[i*4],
235
+ "events": json.loads(current_values[i*4 + 1]),
236
+ "choices": json.loads(current_values[i*4 + 2]),
237
+ "transitions": json.loads(current_values[i*4 + 3])
238
  }
239
  updated_data["masterlocation1"]["end"] = masterlocation1["end"]
240
  return json.dumps(updated_data, indent=2)
 
242
  update_button = gr.Button("Update JSON")
243
  json_output = gr.Textbox(label="Updated JSON", lines=10)
244
 
245
+ update_button.click(update_json, inputs=outputs, outputs=json_output)
246
 
247
  return outputs + [update_button, json_output]
248