Spaces:
Runtime error
Runtime error
File size: 2,524 Bytes
20684dc 9f47e79 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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.
''')
|