Spaces:
Runtime error
Runtime error
kwabs22
commited on
Commit
·
8eafcce
1
Parent(s):
c9ef21a
Trying to simplify
Browse files
app.py
CHANGED
|
@@ -94,6 +94,7 @@ def generate_story_and_timeline(include_media=False):
|
|
| 94 |
|
| 95 |
# Initialize merged timeline with UI and story timelines
|
| 96 |
merged_timeline = ui_timeline + story_timeline
|
|
|
|
| 97 |
|
| 98 |
# Include media-related items if specified
|
| 99 |
if include_media:
|
|
@@ -104,79 +105,27 @@ def generate_story_and_timeline(include_media=False):
|
|
| 104 |
|
| 105 |
# Sort the merged timeline based on the random numbers
|
| 106 |
merged_timeline.sort(key=lambda x: x[0])
|
|
|
|
| 107 |
|
| 108 |
# Create the story
|
| 109 |
story = create_story(merged_timeline)
|
| 110 |
|
| 111 |
# Format the timeline for display
|
| 112 |
formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in merged_timeline])
|
|
|
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
media_file_types = ["image", "video", "audio"]
|
| 117 |
|
| 118 |
def generate_media_file_list(n):
|
| 119 |
return [random.choice(media_file_types) for _ in range(n)]
|
| 120 |
|
| 121 |
-
# def render_media_with_dropdowns(media_files):
|
| 122 |
-
# rendered_output = []
|
| 123 |
-
# for index, media in enumerate(media_files):
|
| 124 |
-
# iframe = f'<iframe src="{media}_source_{index}.html"></iframe>'
|
| 125 |
-
# dropdown = f'''
|
| 126 |
-
# <select>
|
| 127 |
-
# <option value="{media}_source_1">Source 1</option>
|
| 128 |
-
# <option value="{media}_source_2">Source 2</option>
|
| 129 |
-
# <option value="{media}_source_3">Source 3</option>
|
| 130 |
-
# </select>
|
| 131 |
-
# '''
|
| 132 |
-
# rendered_output.append(f"{iframe}{dropdown}")
|
| 133 |
-
# return rendered_output
|
| 134 |
-
|
| 135 |
-
# def save_to_placeholder(rendered_media):
|
| 136 |
-
# placeholder = []
|
| 137 |
-
# for item in rendered_media:
|
| 138 |
-
# placeholder.append(item)
|
| 139 |
-
# return placeholder
|
| 140 |
-
|
| 141 |
# Example usage with and without media-related items
|
| 142 |
-
timeline_with_media, story_with_media = generate_story_and_timeline(include_media=True)
|
| 143 |
-
timeline_without_media, story_without_media = generate_story_and_timeline(include_media=False)
|
| 144 |
-
|
| 145 |
-
# def split_content_into_blocks(timeline):
|
| 146 |
-
# blocks = []
|
| 147 |
-
# current_text_block = []
|
| 148 |
-
|
| 149 |
-
# for entry in timeline.split('\n'):
|
| 150 |
-
# if 'Media -' in entry:
|
| 151 |
-
# # If we have accumulated text, add it as a block
|
| 152 |
-
# if current_text_block:
|
| 153 |
-
# blocks.append((' '.join(current_text_block), 'text'))
|
| 154 |
-
# current_text_block = []
|
| 155 |
-
|
| 156 |
-
# # Extract the iframe and dropdown
|
| 157 |
-
# match = re.search(r'<iframe.*?</select>', entry, re.DOTALL)
|
| 158 |
-
# if match:
|
| 159 |
-
# blocks.append((match.group(), 'iframe'))
|
| 160 |
-
# else:
|
| 161 |
-
# current_text_block.append(entry)
|
| 162 |
-
|
| 163 |
-
# # Add any remaining text as a final block
|
| 164 |
-
# if current_text_block:
|
| 165 |
-
# blocks.append((' '.join(current_text_block), 'text'))
|
| 166 |
-
|
| 167 |
-
# return blocks
|
| 168 |
-
|
| 169 |
-
# def show_elements(text):
|
| 170 |
-
# blocks = split_content_into_blocks(text)
|
| 171 |
-
# outputs = []
|
| 172 |
-
|
| 173 |
-
# for content, block_type in blocks:
|
| 174 |
-
# if block_type == 'text':
|
| 175 |
-
# outputs.append(gr.Markdown(content))
|
| 176 |
-
# elif block_type == 'iframe':
|
| 177 |
-
# outputs.append(gr.HTML(content))
|
| 178 |
-
|
| 179 |
-
# return outputs
|
| 180 |
|
| 181 |
def show_elements(text):
|
| 182 |
# Parse the input text
|
|
@@ -281,9 +230,9 @@ def convert_timeline_to_game_structure(timeline):
|
|
| 281 |
|
| 282 |
return wrapped_structure
|
| 283 |
|
| 284 |
-
def generate_game_structures():
|
| 285 |
-
timeline_with_media, _ = generate_story_and_timeline(include_media=True)
|
| 286 |
-
timeline_without_media, _ = generate_story_and_timeline(include_media=False)
|
| 287 |
|
| 288 |
game_structure_with_media = convert_timeline_to_game_structure(timeline_with_media)
|
| 289 |
game_structure_without_media = convert_timeline_to_game_structure(timeline_without_media)
|
|
@@ -291,16 +240,9 @@ def generate_game_structures():
|
|
| 291 |
return game_structure_with_media, game_structure_without_media
|
| 292 |
|
| 293 |
# Generate and print the game structures
|
| 294 |
-
game_structure_with_media, game_structure_without_media = generate_game_structures()
|
| 295 |
|
| 296 |
-
|
| 297 |
-
#print("Game Structure with Media:")
|
| 298 |
-
#print(json.dumps(game_structure_with_media, indent=2))
|
| 299 |
-
|
| 300 |
-
#print("\nGame Structure without Media:")
|
| 301 |
-
#print(json.dumps(game_structure_without_media, indent=2))
|
| 302 |
-
|
| 303 |
-
def show_game_structure(include_media):
|
| 304 |
if include_media:
|
| 305 |
return json.dumps(game_structure_with_media, indent=2)
|
| 306 |
else:
|
|
@@ -531,23 +473,37 @@ initgameinfo = start_game()
|
|
| 531 |
#-----------------------------------------------------------------------------------------------------------------------------------
|
| 532 |
|
| 533 |
with gr.Blocks() as demo:
|
| 534 |
-
gr.HTML("Main ideas for this space is (June 2024): <
|
|
|
|
| 535 |
with gr.Tab("Skeleton Generator"):
|
| 536 |
gr.HTML("Some Kinds of game skeletons ideas - Timelines, Graph as State machine paths, Economy ecosystem")
|
| 537 |
gr.HTML("One prompt to be used to test models - <br>Please make 10 python lists for the types of media files and their purposes in a game and then use those lists to random generate a timeline of 20 items when the function is called <br>Great next suggest ways to improve this function to create better timelines")
|
| 538 |
-
with gr.
|
| 539 |
-
gr.
|
| 540 |
-
gr.
|
| 541 |
-
with gr.
|
| 542 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
media_checkbox = gr.Checkbox(label="Include Media")
|
| 544 |
output_text = gr.Code(language="json")
|
| 545 |
-
|
|
|
|
|
|
|
| 546 |
media_checkbox.change(
|
| 547 |
fn=show_game_structure,
|
| 548 |
inputs=[media_checkbox],
|
| 549 |
outputs=[output_text]
|
| 550 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
gr.HTML("Splits by new line")
|
| 552 |
input_text = gr.Textbox(label="Input Text", lines=10)
|
| 553 |
output_group = gr.Group()
|
|
@@ -555,15 +511,7 @@ with gr.Blocks() as demo:
|
|
| 555 |
@gr.render(inputs=input_text)
|
| 556 |
def update(text):
|
| 557 |
return show_elements(text)
|
| 558 |
-
gr.Markdown("# Story and Timeline Generator")
|
| 559 |
-
gr.Markdown("Click the button to generate a random timeline and story based on UI elements and story events. <br>Ask an LLM to use this to write a story around")
|
| 560 |
-
|
| 561 |
-
with gr.Row():
|
| 562 |
-
timeline_output = gr.Textbox(label="Timeline", lines=20)
|
| 563 |
-
story_output = gr.Textbox(label="Generated Story", lines=20)
|
| 564 |
|
| 565 |
-
generate_button = gr.Button("Generate Story and Timeline")
|
| 566 |
-
generate_button.click(generate_story_and_timeline, inputs=[], outputs=[timeline_output, story_output])
|
| 567 |
with gr.Tab("Test Example State Machine"):
|
| 568 |
with gr.Tab("Config Without Assets"):
|
| 569 |
with gr.Row():
|
|
|
|
| 94 |
|
| 95 |
# Initialize merged timeline with UI and story timelines
|
| 96 |
merged_timeline = ui_timeline + story_timeline
|
| 97 |
+
no_media_merged_timeline = merged_timeline
|
| 98 |
|
| 99 |
# Include media-related items if specified
|
| 100 |
if include_media:
|
|
|
|
| 105 |
|
| 106 |
# Sort the merged timeline based on the random numbers
|
| 107 |
merged_timeline.sort(key=lambda x: x[0])
|
| 108 |
+
no_media_merged_timeline.sort(key=lambda x: x[0])
|
| 109 |
|
| 110 |
# Create the story
|
| 111 |
story = create_story(merged_timeline)
|
| 112 |
|
| 113 |
# Format the timeline for display
|
| 114 |
formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in merged_timeline])
|
| 115 |
+
no_media_formatted_timeline = "\n".join([f"{entry[0]}: {entry[1]} - {entry[2]}" for entry in no_media_merged_timeline])
|
| 116 |
|
| 117 |
+
game_structure_with_media, game_structure_without_media = generate_game_structures(formatted_timeline, no_media_formatted_timeline)
|
| 118 |
+
|
| 119 |
+
return formatted_timeline, no_media_formatted_timeline, story, game_structure_with_media, game_structure_without_media
|
| 120 |
|
| 121 |
media_file_types = ["image", "video", "audio"]
|
| 122 |
|
| 123 |
def generate_media_file_list(n):
|
| 124 |
return [random.choice(media_file_types) for _ in range(n)]
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
# Example usage with and without media-related items
|
| 127 |
+
# timeline_with_media, story_with_media = generate_story_and_timeline(include_media=True)
|
| 128 |
+
# timeline_without_media, story_without_media = generate_story_and_timeline(include_media=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
def show_elements(text):
|
| 131 |
# Parse the input text
|
|
|
|
| 230 |
|
| 231 |
return wrapped_structure
|
| 232 |
|
| 233 |
+
def generate_game_structures(timeline_with_media, timeline_without_media):
|
| 234 |
+
# timeline_with_media, _ = generate_story_and_timeline(include_media=True)
|
| 235 |
+
# timeline_without_media, _ = generate_story_and_timeline(include_media=False)
|
| 236 |
|
| 237 |
game_structure_with_media = convert_timeline_to_game_structure(timeline_with_media)
|
| 238 |
game_structure_without_media = convert_timeline_to_game_structure(timeline_without_media)
|
|
|
|
| 240 |
return game_structure_with_media, game_structure_without_media
|
| 241 |
|
| 242 |
# Generate and print the game structures
|
| 243 |
+
# game_structure_with_media, game_structure_without_media = generate_game_structures()
|
| 244 |
|
| 245 |
+
def show_game_structure(include_media, game_structure_with_media, game_structure_without_media):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
if include_media:
|
| 247 |
return json.dumps(game_structure_with_media, indent=2)
|
| 248 |
else:
|
|
|
|
| 473 |
#-----------------------------------------------------------------------------------------------------------------------------------
|
| 474 |
|
| 475 |
with gr.Blocks() as demo:
|
| 476 |
+
gr.HTML("""Main ideas for this space is (June 2024): <div style="display: flex; justify-content: space-between; margin-bottom: 20px;">
|
| 477 |
+
<div style="width: 20%;">A program exist around data </div><div style="width: 20%;">We can generate almost any media data and more </div><div style="width: 20%;">llms good at short questions <br>Time moves in a straight so all considerations are flattend by the nature of time </div><div style="width: 20%;">HF + Gradio allows for api use so this my prototype tool for tool use test</div><div style="width: 20%;"></div>""")
|
| 478 |
with gr.Tab("Skeleton Generator"):
|
| 479 |
gr.HTML("Some Kinds of game skeletons ideas - Timelines, Graph as State machine paths, Economy ecosystem")
|
| 480 |
gr.HTML("One prompt to be used to test models - <br>Please make 10 python lists for the types of media files and their purposes in a game and then use those lists to random generate a timeline of 20 items when the function is called <br>Great next suggest ways to improve this function to create better timelines")
|
| 481 |
+
with gr.Accordion("Simplification Struggle"):
|
| 482 |
+
gr.Markdown("# Story and Timeline Generator")
|
| 483 |
+
gr.Markdown("Click the button to generate a random timeline and story based on UI elements and story events. <br>Ask an LLM to use this to write a story around")
|
| 484 |
+
with gr.Row():
|
| 485 |
+
timeline_output_with_assets = gr.Textbox(label="Timeline", lines=20)
|
| 486 |
+
timeline_output = gr.Textbox(label="Timeline", lines=20)
|
| 487 |
+
story_output = gr.Textbox(label="Generated Story", lines=20)
|
| 488 |
+
gr.Textbox("Do all fit on same row")
|
| 489 |
+
|
| 490 |
+
generate_button = gr.Button("Generate Story and Timeline")
|
| 491 |
+
with gr.Accordion("Can copy in the Test Example State Machine tab - only linear path for now"):
|
| 492 |
media_checkbox = gr.Checkbox(label="Include Media")
|
| 493 |
output_text = gr.Code(language="json")
|
| 494 |
+
screen_game_structure_with_media = gr.State()
|
| 495 |
+
screen_game_structure_without_media = gr.State()
|
| 496 |
+
|
| 497 |
media_checkbox.change(
|
| 498 |
fn=show_game_structure,
|
| 499 |
inputs=[media_checkbox],
|
| 500 |
outputs=[output_text]
|
| 501 |
)
|
| 502 |
+
generate_button.click(generate_story_and_timeline, inputs=[], outputs=[timeline_output_with_assets, timeline_output, story_output, screen_game_structure_with_media, screen_game_structure_without_media])
|
| 503 |
+
# with gr.Row():
|
| 504 |
+
# gr.Textbox(value=timeline_with_media, lines=4)
|
| 505 |
+
# gr.Textbox(value=timeline_without_media, lines=4)
|
| 506 |
+
|
| 507 |
gr.HTML("Splits by new line")
|
| 508 |
input_text = gr.Textbox(label="Input Text", lines=10)
|
| 509 |
output_group = gr.Group()
|
|
|
|
| 511 |
@gr.render(inputs=input_text)
|
| 512 |
def update(text):
|
| 513 |
return show_elements(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
|
|
|
|
|
|
| 515 |
with gr.Tab("Test Example State Machine"):
|
| 516 |
with gr.Tab("Config Without Assets"):
|
| 517 |
with gr.Row():
|