kwabs22 commited on
Commit
5509fa5
·
1 Parent(s): c333908

Refactor Proto Assist accordion to absorb mess

Browse files
Files changed (1) hide show
  1. app.py +73 -71
app.py CHANGED
@@ -237,7 +237,7 @@ def create_story(timeline):
237
  story.append(f"The player interacted with {entry[2]}.")
238
  return " ".join(story)
239
 
240
- def generate_story_and_timeline(no_ui_timeline_points=10): # , no_media_timeline_points=5, include_media=True):
241
  # Pick 10 random UI items
242
  random_ui_items = pick_random_items(player_engagement_items, no_ui_timeline_points)
243
 
@@ -271,9 +271,12 @@ def generate_story_and_timeline(no_ui_timeline_points=10): # , no_media_timeline
271
  formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in merged_timeline])
272
  # no_media_formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in no_media_merged_timeline])
273
 
274
- game_structure_with_media = generate_game_structures(formatted_timeline) #, game_structure_without_media = generate_game_structures(formatted_timeline, no_media_formatted_timeline)
 
275
 
276
- return formatted_timeline, story, json.dumps(game_structure_with_media, indent=2) #no_media_formatted_timeline, json.dumps(game_structure_without_media, indent=2) #, game_structure_with_media
 
 
277
 
278
  media_file_types = ["image", "video", "audio"]
279
 
@@ -450,13 +453,55 @@ def convert_timeline_to_game_structure(timeline):
450
 
451
  return wrapped_structure
452
 
453
- def generate_game_structures(timeline_with_media): #, timeline_without_media):
454
 
455
- game_structure_with_media = convert_timeline_to_game_structure(timeline_with_media)
456
- #game_structure_without_media = convert_timeline_to_game_structure(timeline_without_media)
457
 
458
- return game_structure_with_media #, game_structure_without_media
 
459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
 
461
  #-----------------------------------------------------------------------------------------------------------------------------------
462
 
@@ -703,48 +748,6 @@ def refresh_file_explorer():
703
 
704
  #-----------------------------------------------------------------------------------------------------------------------------------
705
 
706
- # def timeline_get_random_suggestions(num_lists, items_per_list):
707
- # """
708
- # Generate random suggestions from a specified number of lists.
709
-
710
- # :param num_lists: Number of lists to consider
711
- # :param items_per_list: Number of items to select from each list
712
- # :return: A list of randomly selected suggestions
713
- # """
714
- # selected_lists = random.sample(all_idea_lists, min(num_lists, len(all_idea_lists)))
715
- # suggestions = []
716
-
717
- # for lst in selected_lists:
718
- # suggestions.extend(random.sample(lst, min(items_per_list, len(lst))))
719
-
720
- # return suggestions
721
-
722
- def timeline_get_random_suggestions(num_lists, items_per_list, include_existing_games, include_multiplayer):
723
- """
724
- Generate random suggestions from a specified number of lists.
725
-
726
- :param num_lists: Number of lists to consider
727
- :param items_per_list: Number of items to select from each list
728
- :param include_existing_games: Whether to include existing game inspiration lists
729
- :param include_multiplayer: Whether to include multiplayer features list
730
- :return: A tuple containing the list of randomly selected suggestions and the names of selected lists
731
- """
732
- available_lists = all_idea_lists.copy()
733
- if not include_existing_games:
734
- available_lists = [lst for lst in available_lists if lst not in existing_game_inspirations]
735
- if not include_multiplayer:
736
- available_lists = [lst for lst in available_lists if lst != multiplayer_features]
737
-
738
- selected_lists = random.sample(available_lists, min(num_lists, len(available_lists)))
739
- suggestions = []
740
- selected_list_names = []
741
-
742
- for lst in selected_lists:
743
- suggestions.extend(random.sample(lst, min(items_per_list, len(lst))))
744
- selected_list_names.append(list_names[all_idea_lists.index(lst)])
745
-
746
- return suggestions, selected_list_names
747
-
748
  #-----------------------------------------------------------------------------------------------------------------------------------
749
 
750
  with gr.Blocks() as demo:
@@ -774,28 +777,27 @@ with gr.Blocks() as demo:
774
  timeline_output_text = gr.Textbox(label="Random Suggestions", lines=10)
775
  timeline_selected_lists_text = gr.Textbox(label="Selected Lists", lines=2)
776
  story_output = gr.Textbox(label="Generated Story (Order might be different for now)", lines=20)
777
- with gr.Row():
778
- generate_no_ui_timeline_points = gr.Slider(minimum=1, value=10, step=1, maximum=30, label="Choose the amount of ui timeline points")
779
- generate_no_media_timeline_points = gr.Slider(minimum=1, value=5, step=1, maximum=30, label="Choose the amount of media timeline points")
780
- generate_with_media_check = gr.Checkbox(label="Generate with media", value=True)
781
- with gr.Row():
782
- timeline_num_lists_slider = gr.Slider(minimum=1, maximum=len(all_idea_lists), step=1, label="Number of Lists to Consider", value=3)
783
- timeline_items_per_list_slider = gr.Slider(minimum=1, maximum=10, step=1, label="Items per List", value=3)
784
- timeline_include_existing_games = gr.Checkbox(label="Include Existing Game Inspirations", value=True)
785
- timeline_include_multiplayer = gr.Checkbox(label="Include Multiplayer Features", value=True)
786
- generate_button = gr.Button("Generate Story and Timeline (Click to get UI that will assist with JSON formatting)")
787
-
788
- @gr.render(inputs=game_structure_output_text_with_media)
789
- def update(game_structure_output_text_with_media):
790
- return show_elements_json_input(game_structure_output_text_with_media)
791
-
792
- generate_button.click(generate_story_and_timeline, inputs=[generate_no_ui_timeline_points], outputs=[timeline_output_with_assets, story_output, game_structure_output_text_with_media]) #, generate_no_media_timeline_points, generate_with_media_check], outputs=[timeline_output_with_assets, timeline_output, story_output, game_structure_output_text_with_media, game_structure_output_text])
793
-
794
- timeline_generate_button = gr.Button("Generate Random Suggestions").click(
795
- timeline_get_random_suggestions,
796
- inputs=[timeline_num_lists_slider, timeline_items_per_list_slider, timeline_include_existing_games, timeline_include_multiplayer],
797
- outputs=[timeline_output_text, timeline_selected_lists_text]
798
- )
799
 
800
  with gr.Accordion("Prompt Engineering as basis for ideation process", open=False):
801
  gr.HTML("Current Assited workflow idea - Story timeline events suggestions (LLM / Premade List) | Merging events with premade mermaid structures (LLM + Story Text + Mermaid Text) | Edit mermaid till satisfied (LLM + Story Text) | Ask LLM to convert to config (LLM + JSON Text) | Edit config (LLM / User with format assistance or not) | Playtest and go back to mermaaid or config if there are problems")
 
237
  story.append(f"The player interacted with {entry[2]}.")
238
  return " ".join(story)
239
 
240
+ def generate_story_and_timeline(no_ui_timeline_points=10, num_lists=1, items_per_list=1, include_existing_games=False, include_multiplayer=False): # , no_media_timeline_points=5, include_media=True):
241
  # Pick 10 random UI items
242
  random_ui_items = pick_random_items(player_engagement_items, no_ui_timeline_points)
243
 
 
271
  formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in merged_timeline])
272
  # no_media_formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in no_media_merged_timeline])
273
 
274
+ # game_structure_with_media = generate_game_structures(formatted_timeline) #, game_structure_without_media = generate_game_structures(formatted_timeline, no_media_formatted_timeline)
275
+ game_structure_with_media = convert_timeline_to_game_structure(formatted_timeline)
276
 
277
+ suggestions, selected_list_names = timeline_get_random_suggestions(num_lists, items_per_list, include_existing_games, include_multiplayer)
278
+
279
+ return formatted_timeline, story, json.dumps(game_structure_with_media, indent=2), suggestions, selected_list_names #no_media_formatted_timeline, json.dumps(game_structure_without_media, indent=2) #, game_structure_with_media
280
 
281
  media_file_types = ["image", "video", "audio"]
282
 
 
453
 
454
  return wrapped_structure
455
 
456
+ # def generate_game_structures(timeline_with_media): #, timeline_without_media):
457
 
458
+ # game_structure_with_media = convert_timeline_to_game_structure(timeline_with_media)
459
+ # #game_structure_without_media = convert_timeline_to_game_structure(timeline_without_media)
460
 
461
+ # return game_structure_with_media #, game_structure_without_media
462
+
463
 
464
+ # def timeline_get_random_suggestions(num_lists, items_per_list):
465
+ # """
466
+ # Generate random suggestions from a specified number of lists.
467
+
468
+ # :param num_lists: Number of lists to consider
469
+ # :param items_per_list: Number of items to select from each list
470
+ # :return: A list of randomly selected suggestions
471
+ # """
472
+ # selected_lists = random.sample(all_idea_lists, min(num_lists, len(all_idea_lists)))
473
+ # suggestions = []
474
+
475
+ # for lst in selected_lists:
476
+ # suggestions.extend(random.sample(lst, min(items_per_list, len(lst))))
477
+
478
+ # return suggestions
479
+
480
+ def timeline_get_random_suggestions(num_lists, items_per_list, include_existing_games, include_multiplayer):
481
+ """
482
+ Generate random suggestions from a specified number of lists.
483
+
484
+ :param num_lists: Number of lists to consider
485
+ :param items_per_list: Number of items to select from each list
486
+ :param include_existing_games: Whether to include existing game inspiration lists
487
+ :param include_multiplayer: Whether to include multiplayer features list
488
+ :return: A tuple containing the list of randomly selected suggestions and the names of selected lists
489
+ """
490
+ available_lists = all_idea_lists.copy()
491
+ if not include_existing_games:
492
+ available_lists = [lst for lst in available_lists if lst not in existing_game_inspirations]
493
+ if not include_multiplayer:
494
+ available_lists = [lst for lst in available_lists if lst != multiplayer_features]
495
+
496
+ selected_lists = random.sample(available_lists, min(num_lists, len(available_lists)))
497
+ suggestions = []
498
+ selected_list_names = []
499
+
500
+ for lst in selected_lists:
501
+ suggestions.extend(random.sample(lst, min(items_per_list, len(lst))))
502
+ selected_list_names.append(list_names[all_idea_lists.index(lst)])
503
+
504
+ return suggestions, selected_list_names
505
 
506
  #-----------------------------------------------------------------------------------------------------------------------------------
507
 
 
748
 
749
  #-----------------------------------------------------------------------------------------------------------------------------------
750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
751
  #-----------------------------------------------------------------------------------------------------------------------------------
752
 
753
  with gr.Blocks() as demo:
 
777
  timeline_output_text = gr.Textbox(label="Random Suggestions", lines=10)
778
  timeline_selected_lists_text = gr.Textbox(label="Selected Lists", lines=2)
779
  story_output = gr.Textbox(label="Generated Story (Order might be different for now)", lines=20)
780
+ with gr.Row():
781
+ generate_no_ui_timeline_points = gr.Slider(minimum=1, value=10, step=1, maximum=30, label="Choose the amount of ui timeline points")
782
+ #generate_no_media_timeline_points = gr.Slider(minimum=1, value=5, step=1, maximum=30, label="Choose the amount of media timeline points")
783
+ #generate_with_media_check = gr.Checkbox(label="Generate with media", value=True)
784
+ with gr.Row():
785
+ timeline_num_lists_slider = gr.Slider(minimum=1, maximum=len(all_idea_lists), step=1, label="Number of Lists to Consider", value=3)
786
+ timeline_items_per_list_slider = gr.Slider(minimum=1, maximum=10, step=1, label="Items per List", value=3)
787
+ timeline_include_existing_games = gr.Checkbox(label="Include Existing Game Inspirations", value=True)
788
+ timeline_include_multiplayer = gr.Checkbox(label="Include Multiplayer Features", value=True)
789
+ timeline_generate_button = gr.Button("Generate Random Suggestions").click(
790
+ timeline_get_random_suggestions,
791
+ inputs=[timeline_num_lists_slider, timeline_items_per_list_slider, timeline_include_existing_games, timeline_include_multiplayer],
792
+ outputs=[timeline_output_text, timeline_selected_lists_text]
793
+ )
794
+ generate_button = gr.Button("Generate Story and Timeline (Click to get UI that will assist with JSON formatting)")
795
+
796
+ @gr.render(inputs=game_structure_output_text_with_media)
797
+ def update(game_structure_output_text_with_media):
798
+ return show_elements_json_input(game_structure_output_text_with_media)
799
+
800
+ generate_button.click(generate_story_and_timeline, inputs=[generate_no_ui_timeline_points, timeline_num_lists_slider, timeline_items_per_list_slider, timeline_include_existing_games, timeline_include_multiplayer], outputs=[timeline_output_with_assets, story_output, game_structure_output_text_with_media, timeline_output_text, timeline_selected_lists_text]) #, generate_no_media_timeline_points, generate_with_media_check], outputs=[timeline_output_with_assets, timeline_output, story_output, game_structure_output_text_with_media, game_structure_output_text])
 
801
 
802
  with gr.Accordion("Prompt Engineering as basis for ideation process", open=False):
803
  gr.HTML("Current Assited workflow idea - Story timeline events suggestions (LLM / Premade List) | Merging events with premade mermaid structures (LLM + Story Text + Mermaid Text) | Edit mermaid till satisfied (LLM + Story Text) | Ask LLM to convert to config (LLM + JSON Text) | Edit config (LLM / User with format assistance or not) | Playtest and go back to mermaaid or config if there are problems")