jitesh commited on
Commit
9372e1c
1 Parent(s): 9f47e79

refactor widgets

Browse files
Files changed (3) hide show
  1. src/create_statistics.py +14 -8
  2. src/lib.py +35 -2
  3. src/probability_emote.py +1 -31
src/create_statistics.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import plotly.express as px
5
  import streamlit as st
6
 
7
- from .lib import initialise_storytelling
8
 
9
 
10
  def run_create_statistics(gen, container_guide, container_param, container_button):
@@ -12,15 +12,21 @@ def run_create_statistics(gen, container_guide, container_param, container_butto
12
  first_sentence, first_emotion, length = initialise_storytelling(
13
  gen, container_guide, container_param, container_button)
14
  # story_till_now = first_sentence
15
- num_generation = container_param.slider(
16
- label='Number of generation', min_value=1, max_value=100, value=5, step=1)
17
- num_tests = container_param.slider(
18
- label='Number of tests', min_value=1, max_value=1000, value=3, step=1)
19
- reaction_weight_mode = container_param.select_slider(
 
 
 
 
 
20
  "Reaction Weight w:", ["Random", "Fixed"])
21
  if reaction_weight_mode == "Fixed":
22
- reaction_weight = container_param.slider(
23
- label='Reaction Weight w', min_value=0.0, max_value=1.0, value=0.5, step=0.01)
 
24
  elif reaction_weight_mode == "Random":
25
  reaction_weight = -1
26
  if container_button.button('Analyse'):
 
4
  import plotly.express as px
5
  import streamlit as st
6
 
7
+ from .lib import initialise_storytelling, set_input
8
 
9
 
10
  def run_create_statistics(gen, container_guide, container_param, container_button):
 
12
  first_sentence, first_emotion, length = initialise_storytelling(
13
  gen, container_guide, container_param, container_button)
14
  # story_till_now = first_sentence
15
+
16
+ num_generation, num_generation0 = set_input(container_param,
17
+ label='Number of generation', min_value=1, max_value=100, value=5, step=1,
18
+ key_slider='num_generation_slider', key_input='num_generation_input',)
19
+
20
+ num_tests, num_tests0 = set_input(container_param,
21
+ label='Number of tests', min_value=1, max_value=1000, value=3, step=1,
22
+ key_slider='num_tests_slider', key_input='num_tests_input',)
23
+
24
+ reaction_weight_mode = container_param.radio(
25
  "Reaction Weight w:", ["Random", "Fixed"])
26
  if reaction_weight_mode == "Fixed":
27
+ reaction_weight, reaction_weight0 = set_input(container_param,
28
+ label='Reaction Weight w', min_value=0.0, max_value=1.0, value=0.5, step=0.01,
29
+ key_slider='w_slider', key_input='w_input',)
30
  elif reaction_weight_mode == "Random":
31
  reaction_weight = -1
32
  if container_button.button('Analyse'):
src/lib.py CHANGED
@@ -27,6 +27,39 @@ def initialise_storytelling(gen, container_guide, container_param, container_but
27
  first_sentence = story_till_now
28
  first_emotion = gen.get_emotion(first_sentence)
29
 
30
- length = container_param.slider(label='Length of the generated sentence',
31
- min_value=1, max_value=100, value=10, step=1)
 
 
32
  return first_sentence, first_emotion, length
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  first_sentence = story_till_now
28
  first_emotion = gen.get_emotion(first_sentence)
29
 
30
+ length, length0 = set_input(container_param,
31
+ label='Length of the sentence',
32
+ min_value=1, max_value=100, value=10, step=1,
33
+ key_slider='length_slider', key_input='length_input',)
34
  return first_sentence, first_emotion, length
35
+
36
+
37
+ def set_input(container_param,
38
+ label, key_slider, key_input,
39
+ min_value=0.,
40
+ max_value=1.,
41
+ value=.5,
42
+ step=.01,):
43
+ def slider2input():
44
+ st.session_state[key_input] = st.session_state[key_slider]
45
+
46
+ def input2slider():
47
+ st.session_state[key_slider] = st.session_state[key_input]
48
+ container_param = container_param.columns([1.1, 1])
49
+ number_input = container_param[0].number_input(
50
+ label=label,
51
+ min_value=min_value,
52
+ max_value=max_value,
53
+ value=value,
54
+ step=step,
55
+ key=key_input,
56
+ on_change=input2slider)
57
+ slider_input = container_param[1].slider(
58
+ label='',
59
+ min_value=min_value,
60
+ max_value=max_value,
61
+ value=value,
62
+ step=step,
63
+ key=key_slider,
64
+ on_change=slider2input)
65
+ return slider_input, number_input
src/probability_emote.py CHANGED
@@ -1,7 +1,7 @@
1
  import numpy as np
2
  import plotly.graph_objects as go
3
  import streamlit as st
4
-
5
 
6
  @st.cache
7
  def get_w(f, ec=0.86, rv=0.50):
@@ -40,7 +40,6 @@ def proper_float(i):
40
  def get_text():
41
  return '''
42
 
43
- ## Description
44
  ### Eric's proposal
45
  > I would propose a scoring metric something like this:
46
  > * `probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty`
@@ -89,35 +88,6 @@ def get_equation_text(w=0.5, ec=0.7, rand=None, emotion_frequency=None):
89
  return text
90
 
91
 
92
- def set_input(container_param,
93
- label, key_slider, key_input,
94
- min_value=0.,
95
- max_value=1.,
96
- value=.5,
97
- step=.01,):
98
- def slider2input():
99
- st.session_state[key_input] = st.session_state[key_slider]
100
-
101
- def input2slider():
102
- st.session_state[key_slider] = st.session_state[key_input]
103
- container_param = container_param.columns([1.1, 1])
104
- slider_input = container_param[1].slider(
105
- label=label,
106
- min_value=min_value,
107
- max_value=max_value,
108
- value=value,
109
- step=step,
110
- key=key_slider,
111
- on_change=slider2input)
112
- number_input = container_param[0].number_input(
113
- label='',
114
- min_value=min_value,
115
- max_value=max_value,
116
- value=value,
117
- step=step,
118
- key=key_input,
119
- on_change=input2slider)
120
- return slider_input, number_input
121
 
122
 
123
  def run_probability_emote(container_param):
 
1
  import numpy as np
2
  import plotly.graph_objects as go
3
  import streamlit as st
4
+ from .lib import set_input
5
 
6
  @st.cache
7
  def get_w(f, ec=0.86, rv=0.50):
 
40
  def get_text():
41
  return '''
42
 
 
43
  ### Eric's proposal
44
  > I would propose a scoring metric something like this:
45
  > * `probability_emote = w * emotion_confidence + (1 - w) * frequency_penalty`
 
88
  return text
89
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
 
93
  def run_probability_emote(container_param):