-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeploy.py
164 lines (111 loc) · 4.73 KB
/
Deploy.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import streamlit as st
import sqlite3
import pandas as pd
import time
from getdata import SQLrepo
from model_s import StockModel
import plotly.express as px
import warnings
warnings.simplefilter(action="ignore", category=FutureWarning)
connection = sqlite3.connect("stocks.sqlite", check_same_thread=False)
repo = SQLrepo(connection=connection)
st.set_page_config(page_title="Stocks App",
page_icon=":moneybag:")
st.markdown(f"<h2 style='text-align: center; '>Stock Returns Prediction ML App</h2>",
unsafe_allow_html=True)
st.markdown(f"<h4 style='text-align: center; '>Daily Updating Our Models and Data</h4>",
unsafe_allow_html=True)
ls_tick = {
"Apple": "AAPL",
"IBM": "IBM",
"Microsoft": "MSFT",
"Google": "GOOG",
"Tesla": "TSLA",
"Amazon": "AMZN",
"META": "META",
}
select_stock = st.selectbox("Stock Selection ", [x for x in ls_tick.keys()])
selection = select_stock
if selection == "none":
st.error("Please select a stock" , icon="🔥")
else:
st.markdown(
f"<h2 style='text-align: center; '>You selected {select_stock} stock</h2>", unsafe_allow_html=True)
col1, col2, col3 = st.columns(3)
with col2:
center_button = st.button('Go', use_container_width=True)
data_flag = False
if center_button:
# make animation
print(f"Button clicked {selection}")
with col2:
with st.spinner(''):
try:
data_prices = repo.read_table(table_name=selection)
st.success("Data loaded successfully", icon="⚡")
data_pred = repo.read_table(table_name=f"{selection}_pred")
data_flag = True
# show prices data on px graph
except Exception as e :
st.error("Please select a stock",icon="🔥")
data_flag = False
def trend(pred, date, pred_str):
"""
Custom function to show trend.
Args:
pred (float): Prediction value as a float.
date (str): String date.
pred_str (str): String prediction value.
"""
if pred >= 0.005:
return st.success(f'Prediction: {pred_str} ✅💯 Verified Up Trend on {date}')
elif pred >= 0:
return st.warning(f'Prediction: {pred_str}🟡 Unconfirmed Up Trend on {date}')
else:
return st.warning(f'Prediction: {pred_str}🔴 Down Trend on {date}')
if data_flag and center_button :
col1, col2, col3 = st.columns(3)
with col1:
fig = px.line(data_prices, x=data_prices.Date, y="Close", title="Close Price")
st.plotly_chart(fig)
col1, col2, col3 = st.columns(3)
with col2:
next_pred_int_1, next_pred_int_2 = float(data_pred['y_pred'].iat[-2] * 100),float(data_pred['y_pred'].iat[-1] * 100)
next_pred_str_1, next_pred_str_2= str(round(next_pred_int_1 , 5)) + "%",str(round(next_pred_int_2, 5)) + "%"
last_pred_date_1,last_pred_date_2 = str(data_pred['index'].iat[-2])[:10],str(data_pred['index'].iat[-1])[:10]
if data_flag and center_button :
st.markdown(f"<h4 style='text-align: center; '>Predictions For {select_stock} Stock〽️ </h4>",unsafe_allow_html=True)
trend(pred=next_pred_int_1,date=last_pred_date_1,pred_str=next_pred_str_1)
trend(pred=next_pred_int_2,date=last_pred_date_2,pred_str=next_pred_str_2)
# footer and Social Media Links
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(f"<h5 style='text-align: center; '>Find me on <a href='https://www.linkedin.com/in/mohamedahmed878/'>LinkedIn</a></h5>",unsafe_allow_html=True)
st.markdown(f"<h6 style='text-align: center; '>📧 Mail me at: [email protected] </h6>",unsafe_allow_html=True)
st.markdown(f"<h6 style='text-align: center; '>📞 Whatsapp me : +201098557840 </h6>",unsafe_allow_html=True)
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(f"<h6 style='text-align: center; '>⚠️ This not a financial advice it's just a Scientific Computing using Machine Learning ⚠️</h6>",unsafe_allow_html=True)
st.markdown(f"<h6 style='text-align: center; '>⚠️ It did a good job in Back testing ⚠️</h6>",unsafe_allow_html=True)