Spaces:
Runtime error
Runtime error
import random | |
import numpy as np | |
import streamlit as st | |
from .lib import initialise_storytelling | |
def run_play_storytelling(gen, container_guide, container_param, container_button): | |
first_sentence, first_emotion, length = initialise_storytelling( | |
gen, container_guide, container_param, container_button) | |
# story_till_now = first_sentence | |
if 'sentence_list' not in st.session_state: | |
st.session_state.sentence_list = [{'sentence': first_sentence, | |
'emotion': first_emotion['label'], | |
'score': first_emotion['score']}] | |
if 'full_story' not in st.session_state: | |
st.session_state.full_story = first_sentence | |
container_button = container_button.columns([1, 1, 1]) | |
heading_container = st.container() | |
col_turn, col_sentence, col_emo = st.columns([1, 8, 2]) | |
if container_button[0].button('Run'): | |
heading_container.markdown(f'### Story') | |
# st.text(story_till_now) | |
full_story, emotion, new_sentence = gen.next_sentence( | |
st.session_state.full_story, length) | |
st.session_state.full_story = full_story | |
st.session_state.sentence_list.append({ | |
'sentence': new_sentence, | |
'emotion': emotion["label"], | |
'score': emotion["score"]}) | |
# col_sentence.markdown(st.session_state.sentence_list) | |
for step in st.session_state.sentence_list: | |
col_turn, col_sentence, col_emo = st.columns([1, 8, 2]) | |
col_sentence.markdown(step['sentence']) | |
col_emo.markdown( | |
f'{step["emotion"]} {np.round(step["score"], 3)}', unsafe_allow_html=False) | |
else: | |
step = st.session_state.sentence_list[0] | |
# col_sentence.markdown(step['sentence']) | |
# col_emo.markdown( | |
# f'{step["emotion"]} {np.round(step["score"], 3)}', unsafe_allow_html=False) | |
container_guide.markdown( | |
'### Write the first sentence and then hit the `Run` button') | |
if container_button[2].button('Clear'): | |
st.session_state.full_story = first_sentence | |
st.session_state.sentence_list = [{'sentence': first_sentence, | |
'emotion': first_emotion['label'], | |
'score': first_emotion['score']}] | |
st.sidebar.markdown( | |
''' | |
* Click `Run` again to generate the next sentence. | |
* Click `Clear` twice to reset the story. | |
''') | |