bills commited on
Commit
a1770fe
1 Parent(s): 8f300cf

Added sessionstate

Browse files
SessionState.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hack to add per-session state to Streamlit.
2
+ Usage
3
+ -----
4
+ >>> import SessionState
5
+ >>>
6
+ >>> session_state = SessionState.get(user_name='', favorite_color='black')
7
+ >>> session_state.user_name
8
+ ''
9
+ >>> session_state.user_name = 'Mary'
10
+ >>> session_state.favorite_color
11
+ 'black'
12
+ Since you set user_name above, next time your script runs this will be the
13
+ result:
14
+ >>> session_state = get(user_name='', favorite_color='black')
15
+ >>> session_state.user_name
16
+ 'Mary'
17
+ """
18
+ from streamlit.script_runner import get_script_run_ctx as get_report_ctx
19
+ from streamlit.server import Server
20
+
21
+
22
+ class SessionState(object):
23
+ def __init__(self, **kwargs):
24
+ """A new SessionState object.
25
+ Parameters
26
+ ----------
27
+ **kwargs : any
28
+ Default values for the session state.
29
+ Example
30
+ -------
31
+ >>> session_state = SessionState(user_name='', favorite_color='black')
32
+ >>> session_state.user_name = 'Mary'
33
+ ''
34
+ >>> session_state.favorite_color
35
+ 'black'
36
+ """
37
+ for key, val in kwargs.items():
38
+ setattr(self, key, val)
39
+
40
+
41
+ def get(**kwargs):
42
+ """Gets a SessionState object for the current session.
43
+ Creates a new object if necessary.
44
+ Parameters
45
+ ----------
46
+ **kwargs : any
47
+ Default values you want to add to the session state, if we're creating a
48
+ new one.
49
+ Example
50
+ -------
51
+ >>> session_state = get(user_name='', favorite_color='black')
52
+ >>> session_state.user_name
53
+ ''
54
+ >>> session_state.user_name = 'Mary'
55
+ >>> session_state.favorite_color
56
+ 'black'
57
+ Since you set user_name above, next time your script runs this will be the
58
+ result:
59
+ >>> session_state = get(user_name='', favorite_color='black')
60
+ >>> session_state.user_name
61
+ 'Mary'
62
+ """
63
+ # Hack to get the session object from Streamlit.
64
+
65
+ ctx = get_report_ctx()
66
+
67
+ this_session = None
68
+
69
+ current_server = Server.get_current()
70
+ if hasattr(current_server, '_session_infos'):
71
+ # Streamlit < 0.56
72
+ session_infos = Server.get_current()._session_infos.values()
73
+ else:
74
+ session_infos = Server.get_current()._session_info_by_id.values()
75
+
76
+ for session_info in session_infos:
77
+ s = session_info.session
78
+ if (
79
+ # Streamlit < 0.54.0
80
+ (hasattr(s, '_main_dg') and s._main_dg == ctx.main_dg)
81
+ or
82
+ # Streamlit >= 0.54.0
83
+ (not hasattr(s, '_main_dg') and s.enqueue == ctx.enqueue)
84
+ or
85
+ # Streamlit >= 0.65.2
86
+ (not hasattr(s, '_main_dg') and s._uploaded_file_mgr == ctx.uploaded_file_mgr)
87
+ ):
88
+ this_session = s
89
+
90
+ if this_session is None:
91
+ raise RuntimeError(
92
+ "Oh noes. Couldn't get your Streamlit Session object. "
93
+ 'Are you doing something fancy with threads?')
94
+
95
+ # Got the session object! Now let's attach some state into it.
96
+
97
+ if not hasattr(this_session, '_custom_session_state'):
98
+ this_session._custom_session_state = SessionState(**kwargs)
99
+
100
+ return this_session._custom_session_state
__pycache__/SessionState.cpython-37.pyc ADDED
Binary file (2.92 kB). View file
 
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import time
2
  import warnings
 
3
  import numpy as np
4
  import pandas as pd
5
  import datetime as dt
@@ -7,19 +8,22 @@ import streamlit as st
7
  import tensorflow as tf
8
  import pandas_datareader as pdr
9
  import matplotlib.pyplot as plt
 
10
  from sklearn.preprocessing import MinMaxScaler
11
  from tensorflow.keras.models import load_model
12
 
13
  # warnings.filterwarnings('ignore')
14
  # plt.style.use('fivethirtyeight')
15
 
 
 
16
  st.set_page_config(
17
  page_title="FANG Stock Prediction",
18
- page_icon=":currency:",
19
  layout="wide"
20
  )
21
 
22
- st.write("# Welcome to FANG Stock Prediction Dashboard :bitcoin:")
23
 
24
  company_ticker = ['FB', 'AAPL', 'TSLA', 'GOOG', 'NVDA']
25
 
@@ -86,7 +90,7 @@ elif selection == 'Actual Stock Price and Model Prediction':
86
  st.line_chart(data_GOOG.filter(['Adj Close'])).add_rows(valid)
87
  st.table(valid)
88
 
89
- real_data = [model_inputs[len(model_inputs) + 2 - prediction_days:len(model_inputs) + 2, 0]]
90
  real_data = np.array(real_data)
91
  real_data = np.reshape(real_data, (real_data.shape[0], real_data.shape[1], 1))
92
 
 
1
  import time
2
  import warnings
3
+ # import SessionState
4
  import numpy as np
5
  import pandas as pd
6
  import datetime as dt
 
8
  import tensorflow as tf
9
  import pandas_datareader as pdr
10
  import matplotlib.pyplot as plt
11
+ from PIL import Image
12
  from sklearn.preprocessing import MinMaxScaler
13
  from tensorflow.keras.models import load_model
14
 
15
  # warnings.filterwarnings('ignore')
16
  # plt.style.use('fivethirtyeight')
17
 
18
+ im = Image.open('bitcoin.png')
19
+
20
  st.set_page_config(
21
  page_title="FANG Stock Prediction",
22
+ page_icon=im,
23
  layout="wide"
24
  )
25
 
26
+ st.write("# Welcome to FANG Stock Prediction Dashboard :man: :coffee:")
27
 
28
  company_ticker = ['FB', 'AAPL', 'TSLA', 'GOOG', 'NVDA']
29
 
 
90
  st.line_chart(data_GOOG.filter(['Adj Close'])).add_rows(valid)
91
  st.table(valid)
92
 
93
+ real_data = [model_inputs[len(model_inputs) + 1 - prediction_days:len(model_inputs) + 1, 0]]
94
  real_data = np.array(real_data)
95
  real_data = np.reshape(real_data, (real_data.shape[0], real_data.shape[1], 1))
96
 
bitcoin.png ADDED