kwabs22 commited on
Commit
9cb6ce3
·
1 Parent(s): 18ead55

editing placeholder debug

Browse files
Files changed (1) hide show
  1. app.py +81 -38
app.py CHANGED
@@ -160,52 +160,95 @@ def show_elements(text):
160
  return outputs
161
 
162
  def show_elements_json_input(json_input):
163
- # Parse the JSON input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  data = json.loads(json_input)
 
165
 
166
  outputs = []
167
 
168
- # Iterate through all locations in the masterlocation1
169
- for location, details in data['masterlocation1'].items():
170
  if location == 'end':
171
  continue
172
 
173
- description = details['description']
174
-
175
- # Split the description, defaulting to 'Unknown' if no colon is present
176
- parts = description.split(': ', 1)
177
- if len(parts) == 2:
178
- block_type, content = parts
179
- else:
180
- block_type = 'Unknown'
181
- content = description
182
-
183
- if block_type == 'UI':
184
- # Create HTML for UI elements
185
- ui_html = f'<div class="ui-element">{content}</div>'
186
- outputs.append(gr.HTML(ui_html))
187
- elif block_type == 'Story':
188
- # Display story elements as Markdown
189
- outputs.append(gr.Markdown(f"**{content}**"))
190
- elif block_type == 'Media':
191
- content_lower = content.lower()
192
- if 'audio' in content_lower:
193
- # Placeholder for audio element
194
- outputs.append(gr.Audio(label=f"Audio: {content}"))
195
- elif 'video' in content_lower:
196
- # Placeholder for video element
197
- outputs.append(gr.Video(label=f"Video: {content}"))
198
- elif 'image' in content_lower:
199
- # Placeholder for image element
200
- outputs.append(gr.Image(label=f"Image: {content}"))
201
- else:
202
- # Default to text for unknown media types
203
- outputs.append(gr.Markdown(f"*Media: {content}*"))
204
- else:
205
- # Handle unknown types as plain text
206
- outputs.append(gr.Markdown(content))
207
 
208
- return outputs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  def convert_timeline_to_game_structure(timeline):
211
  lines = timeline.split('\n')
 
160
  return outputs
161
 
162
  def show_elements_json_input(json_input):
163
+ # # Parse the JSON input
164
+ # data = json.loads(json_input)
165
+
166
+ # outputs = []
167
+
168
+ # # Iterate through all locations in the masterlocation1
169
+ # for location, details in data['masterlocation1'].items():
170
+ # if location == 'end':
171
+ # continue
172
+
173
+ # description = details['description']
174
+
175
+ # # Split the description, defaulting to 'Unknown' if no colon is present
176
+ # parts = description.split(': ', 1)
177
+ # if len(parts) == 2:
178
+ # block_type, content = parts
179
+ # else:
180
+ # block_type = 'Unknown'
181
+ # content = description
182
+
183
+ # if block_type == 'UI':
184
+ # # Create HTML for UI elements
185
+ # ui_html = f'<div class="ui-element">{content}</div>'
186
+ # outputs.append(gr.HTML(ui_html))
187
+ # elif block_type == 'Story':
188
+ # # Display story elements as Markdown
189
+ # outputs.append(gr.Markdown(f"**{content}**"))
190
+ # elif block_type == 'Media':
191
+ # content_lower = content.lower()
192
+ # if 'audio' in content_lower:
193
+ # # Placeholder for audio element
194
+ # outputs.append(gr.Audio(label=f"Audio: {content}"))
195
+ # elif 'video' in content_lower:
196
+ # # Placeholder for video element
197
+ # outputs.append(gr.Video(label=f"Video: {content}"))
198
+ # elif 'image' in content_lower:
199
+ # # Placeholder for image element
200
+ # outputs.append(gr.Image(label=f"Image: {content}"))
201
+ # else:
202
+ # # Default to text for unknown media types
203
+ # outputs.append(gr.Markdown(f"*Media: {content}*"))
204
+ # else:
205
+ # # Handle unknown types as plain text
206
+ # outputs.append(gr.Markdown(content))
207
+
208
+ # return outputs
209
+
210
  data = json.loads(json_input)
211
+ masterlocation1 = data['masterlocation1']
212
 
213
  outputs = []
214
 
215
+ for location, details in masterlocation1.items():
 
216
  if location == 'end':
217
  continue
218
 
219
+ with gr.Accordion(f"Location: {location}"):
220
+ description = gr.Textbox(label="Description", value=details['description'])
221
+ outputs.append(description)
222
+
223
+ events = gr.JSON(label="Events", value=details['events'])
224
+ outputs.append(events)
225
+
226
+ choices = gr.JSON(label="Choices", value=details['choices'])
227
+ outputs.append(choices)
228
+
229
+ transitions = gr.JSON(label="Transitions", value=details['transitions'])
230
+ outputs.append(transitions)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
+ def update_json():
233
+ updated_data = {"masterlocation1": {}}
234
+ for i, location in enumerate(masterlocation1.keys()):
235
+ if location == 'end':
236
+ continue
237
+ updated_data["masterlocation1"][location] = {
238
+ "description": outputs[i*4].value,
239
+ "events": outputs[i*4 + 1].value,
240
+ "choices": outputs[i*4 + 2].value,
241
+ "transitions": outputs[i*4 + 3].value
242
+ }
243
+ updated_data["masterlocation1"]["end"] = masterlocation1["end"]
244
+ return json.dumps(updated_data, indent=2)
245
+
246
+ update_button = gr.Button("Update JSON")
247
+ json_output = gr.JSON(label="Updated JSON")
248
+
249
+ update_button.click(update_json, outputs=json_output)
250
+
251
+ return outputs + [update_button, json_output]
252
 
253
  def convert_timeline_to_game_structure(timeline):
254
  lines = timeline.split('\n')