Spaces:
Sleeping
Sleeping
import gradio as gr | |
from pprint import pprint | |
import json | |
from loguru import logger | |
from dotenv import load_dotenv | |
load_dotenv() | |
import helpers | |
from homeros import do_homeros | |
DEFAULT_STORY_LEN = 3 #default : after how many chunks we force the story to end | |
USE_DEFAULT_SETTINGS = "Go with the defaults" #default : are we using default story config or asking the user | |
''' | |
update settings | |
''' | |
def save_settings(how_many_chunks, go_with_the_defaults, save_params_btn, go_btn, text_input, story_chunk, settings, story): | |
#save settings | |
settings["default_settings"] = go_with_the_defaults == "Go with the defaults" | |
settings["max_len"] = how_many_chunks + 1 | |
#update ui | |
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), settings, story | |
demo = gr.Blocks() | |
with demo: | |
story = gr.State(value = { | |
"uuid" : "", | |
"status" : "not_started", | |
"world": "", | |
"hero": "", | |
"plot": "", | |
"ending": "", | |
"style": "", | |
"voice": "dylan", | |
"storyteller": "general", | |
"chunks" : [], | |
"messages": [], | |
"full_story_audio_ur": "", | |
"full_story_text": "" | |
}) | |
settings = gr.State(value={ | |
"max_len" : DEFAULT_STORY_LEN, | |
"default_settings": USE_DEFAULT_SETTINGS | |
}) | |
with gr.Row(): | |
gr.Markdown(''' | |
# HOMEROS | |
This demo is exploring the future of interactive storytelling. | |
It puts the user in charge and blurs the boundary between the reader and the author. | |
''') | |
with gr.Row(): | |
how_many_chunks = gr.Slider( | |
minimum = 1, | |
value = DEFAULT_STORY_LEN, | |
step = 1, | |
maximum = 10, | |
label = "How long would you like your story to be?", | |
interactive = True | |
) | |
with gr.Row(): | |
go_with_defaults = gr.Radio( | |
label = "Would you like to go with the defaults or should the storyteller ask you about the details?", | |
value = USE_DEFAULT_SETTINGS, | |
choices = [ | |
"Go with the defaults", | |
"I want full control" | |
], | |
interactive = True | |
) | |
with gr.Row(): | |
text_input = gr.Textbox( | |
label="you say", | |
visible=False | |
) | |
with gr.Row(): | |
story_chunk = gr.Audio( | |
label="storyteller says", | |
interactive=False, | |
autoplay=True, | |
visible=False | |
) | |
with gr.Row(): | |
go_btn = gr.Button( | |
value="Tell the story!", | |
visible=False | |
) | |
go_btn.click( | |
do_homeros, | |
inputs=[text_input, story, settings], | |
outputs=[story_chunk, story, settings] | |
) | |
with gr.Row(): | |
save_params_btn = gr.Button("Save Settings") | |
save_params_btn.click( | |
save_settings, | |
inputs=[how_many_chunks, go_with_defaults, save_params_btn, go_btn, story_chunk, text_input, settings, story], | |
outputs=[how_many_chunks, go_with_defaults, save_params_btn, go_btn, story_chunk, text_input, settings, story] | |
) | |
demo.queue( | |
concurrency_count=5 | |
) | |
demo.launch( | |
server_name="0.0.0.0", | |
ssl_verify=False, | |
show_api=False | |
) | |