File size: 2,815 Bytes
11aef54
 
 
14b9509
7ffa148
11aef54
 
 
 
 
 
 
 
 
 
 
 
 
7ffa148
 
11aef54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
001b448
 
03303ea
 
 
 
 
001b448
7d535df
001b448
 
 
11aef54
7d535df
6fda47f
3a6e456
 
 
09bdbbc
3a6e456
56dae1b
3a6e456
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
import streamlit as st
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import telebot
from keras.models import Sequential
from keras.layers import LSTM
from keras.layers import Dropout
from keras.layers import Dense
import numpy
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from sklearn.metrics import mean_squared_error as mse
import yfinance as yf
import telebot
from keras.models import load_model
import datetime

k='6919541100:AAFhyMD2AbL62FQ2v5MixJTiUve877w2YEE'
bot=telebot.TeleBot(k, parse_mode=None)

def sty(sos):
    head, sep, tail=sos.partition(' ')
    split=head.split('-')
    y, m, d=int(split[0]), int(split[1]), int(split[2])
    return datetime.datetime(year=y, month=m, day=d)

def hey(df):
    #df=do[[0, 1, 2]]
    #df=df[['Date', 'Open', 'Close']]
    df.reset_index(drop=False, inplace=True)
    #df=MinMaxScaler(feature_range=(0, 1)).fit_transform(df)
    #df['Date']=df['Date'].apply(sty)
    X=df[['Open']]
    X=X.to_numpy()
    X=X.astype(np.float32)
    y=df[['Close']]
    Y=y.to_numpy()
    #Y=y.reshape(-1, 1)
    Y=Y.astype(np.float32)
    X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)
    
    sc=MinMaxScaler(feature_range=(0, 1))
    X_train=sc.fit_transform(X_train)
    X_test=sc.transform(X_test)
    #model=load_model('lstm3.keras')
    model = Sequential()
    model.add(LSTM(units=64,return_sequences=True, input_shape=(X_train.shape[1], 1)))
    model.add(Dropout(0.2))
    model.add(LSTM(units=64,return_sequences=True))
    model.add(Dropout(0.2))
    model.add(LSTM(units=32,return_sequences=True))
    model.add(Dropout(0.2))
    model.add(LSTM(units=32))
    model.add(Dropout(0.2))
    model.add(Dense(units=1))
    model.compile(optimizer='adam',loss='mse')
    model.fit(X_train,y_train,epochs=4,batch_size=2)
    y_pr=model.predict(X_test)
    #rmse=sqrt(mse(y_test, y_pr))
    #print(y_pr)
    #print(X_test)
    return model.predict([[df['Open'].iloc[-1]]])

def yff(coin):
    bb=yf.Ticker(coin)
    d=bb.history(period='max')
    return d

tok='6432200967:AAFjrIZ_I6XOEfbxCRJVz9giK2fXRysfptA'
bot = telebot.TeleBot(tok, parse_mode=None)

st.button("Reset", type="primary")
if st.button('Say hello'):
    st.write('Why hello there')
else:
    st.write('Goodbye')

def hey():
        @bot.message_handler(commands=['start', 'help'])
        def send_welcome(message):
	        bot.reply_to(message, hey(yff(message.text)) )
        bot.infinity_polling()
st.button('Click me', on_click=hey)
#option = webdriver.ChromeOptions()
#browser = webdriver.Chrome(service=s, options=option)
#def het():
    
    #browser.get('http://www.google.com')

#st.button('Click you', on_click=het)