jitesh commited on
Commit
1115bb5
1 Parent(s): e82c355

adds download button

Browse files
Files changed (3) hide show
  1. src/lib.py +26 -4
  2. src/read_logs.py +2 -2
  3. src/test.py +7 -0
src/lib.py CHANGED
@@ -4,8 +4,30 @@ import streamlit as st
4
 
5
  from src import StoryGenerator
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # @st.cache(allow_output_mutation=True)
 
 
9
  def initialise_storytelling(gen, container_guide, container_param, container_button):
10
  gen.initialise_models()
11
  choices_first_sentence = [
@@ -30,9 +52,9 @@ def initialise_storytelling(gen, container_guide, container_param, container_but
30
  first_emotion = gen.get_emotion(first_sentence)
31
 
32
  length = set_input(container_param,
33
- label='Length of the sentence',
34
- min_value=1, max_value=100, value=10, step=1,
35
- key_slider='length_slider', key_input='length_input',)
36
  return first_sentence, first_emotion, length
37
 
38
 
@@ -65,4 +87,4 @@ def set_input(container_param,
65
  step=step,
66
  key=key_slider,
67
  on_change=slider2input)
68
- return number_input
 
4
 
5
  from src import StoryGenerator
6
 
7
+ import xlsxwriter
8
+ import pandas as pd
9
+ import io
10
+
11
+
12
+ def create_dowload_button(data, sheet_name='AllData', label="Download data", file_name='data.xlsx'):
13
+
14
+ buffer = io.BytesIO()
15
+ with pd.ExcelWriter(buffer, engine='xlsxwriter') as writer:
16
+ # Write each dataframe to a different worksheet.
17
+ data.to_excel(writer, sheet_name=sheet_name)
18
+
19
+ # Close the Pandas Excel writer and output the Excel file to the buffer
20
+ writer.save()
21
+ st.download_button(
22
+ label=label,
23
+ data=buffer,
24
+ file_name=file_name,
25
+ mime='application/vnd.ms-excel',
26
+ )
27
 
28
  # @st.cache(allow_output_mutation=True)
29
+
30
+
31
  def initialise_storytelling(gen, container_guide, container_param, container_button):
32
  gen.initialise_models()
33
  choices_first_sentence = [
 
52
  first_emotion = gen.get_emotion(first_sentence)
53
 
54
  length = set_input(container_param,
55
+ label='Length of the sentence',
56
+ min_value=1, max_value=100, value=10, step=1,
57
+ key_slider='length_slider', key_input='length_input',)
58
  return first_sentence, first_emotion, length
59
 
60
 
 
87
  step=step,
88
  key=key_slider,
89
  on_change=slider2input)
90
+ return number_input
src/read_logs.py CHANGED
@@ -5,7 +5,7 @@ import plotly.express as px
5
  import streamlit as st
6
  import xlsxwriter
7
  from os import listdir
8
- from .lib import set_input
9
  from os.path import isfile, join, exists
10
  import printj
11
 
@@ -163,12 +163,12 @@ class LogAnalyser:
163
  elif table_mode == 'Table':
164
  st.table(dfs)
165
  # st.table(df_reaction_pattern.iloc[story_id-1])
 
166
  # print(dfs.render())
167
  if table_mode == 'Dataframe':
168
  st.dataframe(df_reaction_pattern)
169
  elif table_mode == 'Table':
170
  st.table(df_reaction_pattern)
171
-
172
  # @st.cache
173
  def dfstyle_color_text_col(self, s):
174
  result = ['background-color: white']*len(s)
 
5
  import streamlit as st
6
  import xlsxwriter
7
  from os import listdir
8
+ from .lib import set_input, create_dowload_button
9
  from os.path import isfile, join, exists
10
  import printj
11
 
 
163
  elif table_mode == 'Table':
164
  st.table(dfs)
165
  # st.table(df_reaction_pattern.iloc[story_id-1])
166
+ create_dowload_button(dfs, sheet_name=f'story_{story_id}', file_name=f'data_story_{story_id}.xlsx')
167
  # print(dfs.render())
168
  if table_mode == 'Dataframe':
169
  st.dataframe(df_reaction_pattern)
170
  elif table_mode == 'Table':
171
  st.table(df_reaction_pattern)
 
172
  # @st.cache
173
  def dfstyle_color_text_col(self, s):
174
  result = ['background-color: white']*len(s)
src/test.py CHANGED
@@ -27,7 +27,14 @@ for i in range(len(s)-1):
27
 
28
  g2p
29
 
 
 
 
 
 
30
 
 
 
31
  # # def highlight_greaterthan(s,column):
32
  # # is_max = pd.Series(data=False, index=s.index)
33
  # # is_max[column] = s.loc[column] >= 1
 
27
 
28
  g2p
29
 
30
+ # %%
31
+ # import plotly.express as px
32
+ from plotly.offline import init_notebook_mode, iplot
33
+ import numpy as np
34
+ init_notebook_mode()
35
 
36
+ x = np.linspace(0, 1)
37
+ iplot([{'x': x, 'y': 1-np.exp(-x)}])
38
  # # def highlight_greaterthan(s,column):
39
  # # is_max = pd.Series(data=False, index=s.index)
40
  # # is_max[column] = s.loc[column] >= 1