import random import streamlit as st from src import StoryGenerator import xlsxwriter import pandas as pd import io def create_dowload_button(data, sheet_name='AllData', label="Download data", file_name='data.xlsx'): buffer = io.BytesIO() with pd.ExcelWriter(buffer, engine='xlsxwriter') as writer: # Write each dataframe to a different worksheet. data.to_excel(writer, sheet_name=sheet_name) # Close the Pandas Excel writer and output the Excel file to the buffer writer.save() st.download_button( label=label, data=buffer, file_name=file_name, mime='application/vnd.ms-excel', ) # @st.cache(allow_output_mutation=True) def initialise_storytelling(gen, container_guide, container_param, container_button): gen.initialise_models() choices_first_sentence = [ 'Custom', 'Hello, I\'m a language model,', 'So I suppose you want to ask me how I did it.', 'I always wanted to be a giraffe - until that night.', 'My first tutor was a dragon with a terrible sense of humor.', 'Doctors told her she could never diet again.', 'Memory is all around us, as well as within.', ] cfs = st.selectbox('Choose First Sentence', choices_first_sentence) if cfs == 'Custom': story_till_now = st.text_input( label='First Sentence', key='first_sentence') else: st.session_state.first_sentence = cfs story_till_now = cfs first_sentence = story_till_now first_emotion = gen.get_emotion(first_sentence) length = set_input(container_param, label='Length of the sentence', min_value=1, max_value=100, value=10, step=1, key_slider='length_slider', key_input='length_input',) return first_sentence, first_emotion, length # @st.cache(allow_output_mutation=True) def set_input(container_param, label, key_slider, key_input, min_value=0., max_value=1., value=.5, step=.01,): def slider2input(): st.session_state[key_input] = st.session_state[key_slider] def input2slider(): st.session_state[key_slider] = st.session_state[key_input] container_param = container_param.columns([1.1, 1]) number_input = container_param[0].number_input( label=label, min_value=min_value, max_value=max_value, value=value, step=step, key=key_input, on_change=input2slider) slider_input = container_param[1].slider( label='', min_value=min_value, max_value=max_value, value=value, step=step, key=key_slider, on_change=slider2input) return number_input