Spaces:
Runtime error
Runtime error
kwabs22
commited on
Commit
·
0e03629
1
Parent(s):
83e773c
media handling brainstorming
Browse files
app.py
CHANGED
|
@@ -98,8 +98,8 @@ def generate_story_and_timeline(include_media=False):
|
|
| 98 |
# Include media-related items if specified
|
| 99 |
if include_media:
|
| 100 |
media_files = generate_media_file_list(5)
|
| 101 |
-
rendered_media = render_media_with_dropdowns(media_files)
|
| 102 |
-
media_timeline = generate_timeline(
|
| 103 |
merged_timeline += media_timeline
|
| 104 |
|
| 105 |
# Sort the merged timeline based on the random numbers
|
|
@@ -118,63 +118,94 @@ media_file_types = ["image", "video", "audio"]
|
|
| 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 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
def save_to_placeholder(rendered_media):
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 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 |
-
|
| 147 |
-
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
def show_elements(text):
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
outputs = []
|
| 172 |
|
| 173 |
-
for
|
| 174 |
-
if block_type == '
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
outputs.append(gr.HTML(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
return outputs
|
| 180 |
|
|
@@ -520,7 +551,7 @@ with gr.Blocks() as demo:
|
|
| 520 |
def update(text):
|
| 521 |
return show_elements(text)
|
| 522 |
with gr.Tab("Conversion of game version"):
|
| 523 |
-
gr.HTML("Can copy in the
|
| 524 |
media_checkbox = gr.Checkbox(label="Include Media")
|
| 525 |
output_text = gr.Code(language="json")
|
| 526 |
|
|
@@ -539,34 +570,64 @@ with gr.Blocks() as demo:
|
|
| 539 |
|
| 540 |
generate_button = gr.Button("Generate Story and Timeline")
|
| 541 |
generate_button.click(generate_story_and_timeline, inputs=[], outputs=[timeline_output, story_output])
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
)
|
| 558 |
-
with gr.Column(scale=1):
|
| 559 |
-
gr.Markdown("# Debugging")
|
| 560 |
-
error_box = gr.Textbox(label="Path Errors", lines=4, value=path_errors)
|
| 561 |
-
with gr.Accordion("Config (Game Spoiler)", open=False):
|
| 562 |
-
custom_config = gr.Textbox(label="Custom Configuration (JSON)", value=json.dumps(all_states, default=lambda o: o.__dict__, indent=2), lines=8)
|
| 563 |
-
custom_configbtn = gr.Button("Load Custom Config")
|
| 564 |
-
|
| 565 |
-
custom_configbtn.click(
|
| 566 |
-
load_game,
|
| 567 |
-
inputs=[custom_config],
|
| 568 |
-
outputs=[error_box, game_log, description, choices, game_session, custom_config]
|
| 569 |
-
)
|
| 570 |
with gr.Tab("Custom JS Config Creator"):
|
| 571 |
gr.HTML("Companion Space for zerogpu / client api workflow planning for a way to send a zip to the Basic Game Engine at the bottom of https://huggingface.co/spaces/KwabsHug/TestSvelteStatic (Also to test how much can be done majority on cpu)")
|
| 572 |
with gr.Tab("Simple Config Creator"):
|
|
@@ -688,9 +749,10 @@ with gr.Blocks() as demo:
|
|
| 688 |
gr.HTML("Placeholder for models small enough to run on cpu here in this space that can assist")
|
| 689 |
|
| 690 |
with gr.Tab("Shaders and related"):
|
|
|
|
| 691 |
gr.HTML("Post-processing Effects, material effects, Particle systems, visual feedback")
|
| 692 |
gr.HTML("Visual Effects - eg. explosion can turn all items white for a moment, losing conciousness blurs whole screen")
|
| 693 |
-
gr.HTML("Placeholder for huggingface spaces that can assist")
|
| 694 |
gr.HTML("Placeholder for models small enough to run on cpu here in this space that can assist")
|
| 695 |
|
| 696 |
with gr.Tab("Other Considerations"):
|
|
@@ -714,6 +776,27 @@ with gr.Blocks() as demo:
|
|
| 714 |
gr.Image(value="testmedia/Flash scribble SDXL - random squiggles as roads.webp")
|
| 715 |
gr.Video(value="testmedia/SVD - random squiggles as roads video 004484.mp4")
|
| 716 |
gr.Audio(value="testmedia/Stable Audio - Raindrops, output.wav")
|
| 717 |
-
gr.HTML("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
|
| 719 |
demo.launch()
|
|
|
|
| 98 |
# Include media-related items if specified
|
| 99 |
if include_media:
|
| 100 |
media_files = generate_media_file_list(5)
|
| 101 |
+
#rendered_media = render_media_with_dropdowns(media_files)
|
| 102 |
+
media_timeline = generate_timeline(media_files, "Media")
|
| 103 |
merged_timeline += media_timeline
|
| 104 |
|
| 105 |
# Sort the merged timeline based on the random numbers
|
|
|
|
| 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
|
| 183 |
+
pattern = r'(\d+): (UI|Story|Media) - (.+)'
|
| 184 |
+
blocks = re.findall(pattern, text)
|
| 185 |
+
|
| 186 |
+
# Sort blocks by their timestamp
|
| 187 |
+
blocks.sort(key=lambda x: int(x[0]))
|
| 188 |
+
|
| 189 |
outputs = []
|
| 190 |
|
| 191 |
+
for timestamp, block_type, content in blocks:
|
| 192 |
+
if block_type == 'UI':
|
| 193 |
+
# Create HTML for UI elements
|
| 194 |
+
ui_html = f'<div class="ui-element">{content}</div>'
|
| 195 |
+
outputs.append(gr.HTML(ui_html))
|
| 196 |
+
elif block_type == 'Story':
|
| 197 |
+
# Display story elements as Markdown
|
| 198 |
+
outputs.append(gr.Markdown(f"**{content}**"))
|
| 199 |
+
elif block_type == 'Media':
|
| 200 |
+
if content.lower() == 'audio':
|
| 201 |
+
# Placeholder for audio element
|
| 202 |
+
outputs.append(gr.Audio(label=f"Audio at {timestamp} in the order"))
|
| 203 |
+
elif content.lower() == 'video':
|
| 204 |
+
# Placeholder for video element
|
| 205 |
+
outputs.append(gr.Video(label=f"Video at {timestamp} in the order"))
|
| 206 |
+
elif content.lower() == 'image':
|
| 207 |
+
# Placeholder for image element
|
| 208 |
+
outputs.append(gr.Image(label=f"Image at {timestamp} in the order"))
|
| 209 |
|
| 210 |
return outputs
|
| 211 |
|
|
|
|
| 551 |
def update(text):
|
| 552 |
return show_elements(text)
|
| 553 |
with gr.Tab("Conversion of game version"):
|
| 554 |
+
gr.HTML("Can copy in the Test Example State Machine tab - only linear path for now")
|
| 555 |
media_checkbox = gr.Checkbox(label="Include Media")
|
| 556 |
output_text = gr.Code(language="json")
|
| 557 |
|
|
|
|
| 570 |
|
| 571 |
generate_button = gr.Button("Generate Story and Timeline")
|
| 572 |
generate_button.click(generate_story_and_timeline, inputs=[], outputs=[timeline_output, story_output])
|
| 573 |
+
with gr.Tab("Test Example State Machine"):
|
| 574 |
+
with gr.Tab("Config Without Assets"):
|
| 575 |
+
with gr.Row():
|
| 576 |
+
with gr.Column(scale=2):
|
| 577 |
+
gr.Markdown("# Text-based Adventure Game")
|
| 578 |
+
|
| 579 |
+
description = gr.Textbox(label="Current Situation", lines=4, value=initgameinfo[0])
|
| 580 |
+
media = gr.HTML("Placeholder to load all media tests")
|
| 581 |
+
choices = gr.Radio(label="Your Choices", choices=initgameinfo[1])
|
| 582 |
+
submit_btn = gr.Button("Make Choice")
|
| 583 |
+
game_log = gr.Textbox(label="Game Log", lines=20, value=initgameinfo[2])
|
| 584 |
+
game_session = gr.State(value=initgameinfo[3])
|
| 585 |
+
submit_btn.click(
|
| 586 |
+
make_choice,
|
| 587 |
+
inputs=[choices, game_session],
|
| 588 |
+
outputs=[description, choices, game_log, game_session]
|
| 589 |
+
)
|
| 590 |
+
with gr.Column(scale=1):
|
| 591 |
+
gr.Markdown("# Debugging")
|
| 592 |
+
error_box = gr.Textbox(label="Path Errors", lines=4, value=path_errors)
|
| 593 |
+
with gr.Accordion("Config (Game Spoiler and Example for llm to remix)", open=False):
|
| 594 |
+
custom_config = gr.Textbox(label="Custom Configuration (JSON)", value=json.dumps(all_states, default=lambda o: o.__dict__, indent=2), lines=8)
|
| 595 |
+
custom_configbtn = gr.Button("Load Custom Config")
|
| 596 |
+
|
| 597 |
+
custom_configbtn.click(
|
| 598 |
+
load_game,
|
| 599 |
+
inputs=[custom_config],
|
| 600 |
+
outputs=[error_box, game_log, description, choices, game_session, custom_config]
|
| 601 |
+
)
|
| 602 |
+
with gr.Tab("Config With Assets"):
|
| 603 |
+
gr.HTML("Placeholder as not complete yet (still only text)")
|
| 604 |
+
with gr.Row():
|
| 605 |
+
with gr.Column(scale=2):
|
| 606 |
+
gr.Markdown("# Text-based Adventure Game")
|
| 607 |
+
|
| 608 |
+
wadescription = gr.Textbox(label="Current Situation", lines=4, value=initgameinfo[0])
|
| 609 |
+
wamedia = gr.HTML("Placeholder to load all media tests")
|
| 610 |
+
wachoices = gr.Radio(label="Your Choices", choices=initgameinfo[1])
|
| 611 |
+
wasubmit_btn = gr.Button("Make Choice")
|
| 612 |
+
wagame_log = gr.Textbox(label="Game Log", lines=20, value=initgameinfo[2])
|
| 613 |
+
wagame_session = gr.State(value=initgameinfo[3])
|
| 614 |
+
wasubmit_btn.click(
|
| 615 |
+
make_choice,
|
| 616 |
+
inputs=[wachoices, wagame_session],
|
| 617 |
+
outputs=[wadescription, wachoices, wagame_log, wagame_session]
|
| 618 |
+
)
|
| 619 |
+
with gr.Column(scale=1):
|
| 620 |
+
gr.Markdown("# Debugging")
|
| 621 |
+
waerror_box = gr.Textbox(label="Path Errors", lines=4, value=path_errors)
|
| 622 |
+
with gr.Accordion("Config (Game Spoiler and Example for llm to remix)", open=False):
|
| 623 |
+
wacustom_config = gr.Textbox(label="Custom Configuration (JSON)", value=json.dumps(all_states, default=lambda o: o.__dict__, indent=2), lines=8)
|
| 624 |
+
wacustom_configbtn = gr.Button("Load Custom Config")
|
| 625 |
+
|
| 626 |
+
wacustom_configbtn.click(
|
| 627 |
+
load_game,
|
| 628 |
+
inputs=[wacustom_config],
|
| 629 |
+
outputs=[waerror_box, wagame_log, wadescription, wachoices, wagame_session, wacustom_config]
|
| 630 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
with gr.Tab("Custom JS Config Creator"):
|
| 632 |
gr.HTML("Companion Space for zerogpu / client api workflow planning for a way to send a zip to the Basic Game Engine at the bottom of https://huggingface.co/spaces/KwabsHug/TestSvelteStatic (Also to test how much can be done majority on cpu)")
|
| 633 |
with gr.Tab("Simple Config Creator"):
|
|
|
|
| 749 |
gr.HTML("Placeholder for models small enough to run on cpu here in this space that can assist")
|
| 750 |
|
| 751 |
with gr.Tab("Shaders and related"):
|
| 752 |
+
gr.HTML("Any output that is not understood by the common person can be used as special effects eg. depth map filters on images etc.")
|
| 753 |
gr.HTML("Post-processing Effects, material effects, Particle systems, visual feedback")
|
| 754 |
gr.HTML("Visual Effects - eg. explosion can turn all items white for a moment, losing conciousness blurs whole screen")
|
| 755 |
+
gr.HTML("Placeholder for huggingface spaces that can assist - https://huggingface.co/spaces/EPFL-VILAB/4M ")
|
| 756 |
gr.HTML("Placeholder for models small enough to run on cpu here in this space that can assist")
|
| 757 |
|
| 758 |
with gr.Tab("Other Considerations"):
|
|
|
|
| 776 |
gr.Image(value="testmedia/Flash scribble SDXL - random squiggles as roads.webp")
|
| 777 |
gr.Video(value="testmedia/SVD - random squiggles as roads video 004484.mp4")
|
| 778 |
gr.Audio(value="testmedia/Stable Audio - Raindrops, output.wav")
|
| 779 |
+
gr.HTML("""
|
| 780 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 20px;">
|
| 781 |
+
<div style="width: 30%;">
|
| 782 |
+
<img src="testmedia/Flash scribble SDXL - random squiggles as roads.webp" alt="Random squiggles as roads" style="width: 100%; height: auto;">
|
| 783 |
+
</div>
|
| 784 |
+
<div style="width: 30%;">
|
| 785 |
+
<video width="100%" height="auto" controls>
|
| 786 |
+
<source src="testmedia/SVD - random squiggles as roads video 004484.mp4" type="video/mp4">
|
| 787 |
+
Your browser does not support the video tag.
|
| 788 |
+
</video>
|
| 789 |
+
</div>
|
| 790 |
+
<div style="width: 30%;">
|
| 791 |
+
<audio controls style="width: 100%;">
|
| 792 |
+
<source src="testmedia/Stable Audio - Raindrops, output.wav" type="audio/wav">
|
| 793 |
+
Your browser does not support the audio element.
|
| 794 |
+
</audio>
|
| 795 |
+
</div>
|
| 796 |
+
</div>
|
| 797 |
+
<div>
|
| 798 |
+
<p>This is a placeholder to test use as an all-media loader for ease of prototyping.</p>
|
| 799 |
+
</div>
|
| 800 |
+
""")
|
| 801 |
|
| 802 |
demo.launch()
|