File size: 2,694 Bytes
644c96b
86f2d3a
644c96b
86f2d3a
 
644c96b
86f2d3a
 
 
 
 
 
 
 
 
644c96b
86f2d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644c96b
86f2d3a
 
644c96b
86f2d3a
 
 
644c96b
86f2d3a
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from story_gen import StoryGenerator

st.set_page_config(page_title='Storytelling ' +
                   u'\U0001F5BC', page_icon=u'\U0001F5BC', layout="wide")

gen = StoryGenerator()
container_mode = st.sidebar.container()
container_param = st.sidebar.container()
container_button = st.sidebar.container()
mode = container_mode.radio(
    "Select your mode",
    ('Create Statistics', 'Play Storytelling'), index=0)
story_till_now = container_param.text_input(
    label='First Sentence', value='Hello, I\'m a language model,')

num_generation = container_param.slider(
    label='Number of generation', min_value=1, max_value=100, value=10, step=1)
length = container_param.slider(label='Length of the generated sentence',
                                min_value=1, max_value=100, value=20, step=1)
if mode == 'Create Statistics':
    container_mode.write('You selected statistics.')
    num_tests = container_param.slider(
        label='Number of tests', min_value=1, max_value=1000, value=3, step=1)
    reaction_weight_mode = container_param.select_slider(
        "Reaction Weight w:", ["Random", "Fixed"])
    if reaction_weight_mode == "Fixed":
        reaction_weight = container_param.slider(
            label='reaction_weight w', min_value=0, max_value=1, value=-1, step=.001)
    elif reaction_weight_mode == "Random":
        reaction_weight = -1
    if container_button.button('Analyse'):
        gen.get_stats(story_till_now="Hello, I'm a language model,",
                      num_generation=num_generation, length=length, reaction_weight=reaction_weight, num_tests=num_tests)
        if len(gen.stories) > 0:
            for si, story in enumerate(gen.stories):
                st.markdown(f'Story no. {si}:', unsafe_allow_html=False)
                st.markdown(story, unsafe_allow_html=False)

elif mode == 'Create Statistics':
    container_mode.write('Let\'s play storytelling.')

    # # , placeholder="Start writing your story...")
    # story_till_now = st.text_input(
    #     label='First Sentence', value='Hello, I\'m a language model,')

    # num_generation = st.sidebar.slider(
    #     label='Number of generation', min_value=1, max_value=100, value=10, step=1)
    # length = st.sidebar.slider(label='Length of the generated sentence',
    #                            min_value=1, max_value=100, value=20, step=1)
    if container_button.button('Run'):
        story_till_now, emotion = gen.story(
            story_till_now, num_generation, length)
        st.write('Story:')
        st.text(story_till_now)
        st.text(f'Emotion: {emotion}')
    else:
        st.write('Write the first sentence and then hit the Run button')