Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import hopsworks
|
4 |
+
import joblib
|
5 |
+
import datetime
|
6 |
+
import yfinance as yf
|
7 |
+
from pandas_datareader import data as pdr
|
8 |
+
|
9 |
+
project = hopsworks.login()
|
10 |
+
fs = project.get_feature_store()
|
11 |
+
|
12 |
+
mr = project.get_model_registry()
|
13 |
+
model = mr.get_model("btc_model", version=1)
|
14 |
+
model_dir = model.download()
|
15 |
+
model = joblib.load(model_dir + "/btc_model.pkl")
|
16 |
+
|
17 |
+
|
18 |
+
def predict():
|
19 |
+
today = get_date()
|
20 |
+
|
21 |
+
yf.pdr_override()
|
22 |
+
btc_df = pdr.get_data_yahoo('BTC-USD', start=today)
|
23 |
+
btc_df.drop(columns=['Adj Close'], inplace=True)
|
24 |
+
|
25 |
+
btc_df['Dayofyear'] = btc_df.index.dayofyear
|
26 |
+
btc_df['Month'] = btc_df.index.month
|
27 |
+
btc_df['Year'] = btc_df.index.year
|
28 |
+
# btc_df['Date'] = btc_df.index.strftime('%Y-%m-%d %H:%M:%S')
|
29 |
+
|
30 |
+
price = model.predict(btc_df.drop(columns=['close']))[0]
|
31 |
+
return [today, price]
|
32 |
+
|
33 |
+
|
34 |
+
def get_date():
|
35 |
+
today = datetime.datetime.today()
|
36 |
+
return today.date()
|
37 |
+
|
38 |
+
|
39 |
+
demo = gr.Interface(
|
40 |
+
fn=predict,
|
41 |
+
title="Bitcoin Closing Price Prediction",
|
42 |
+
description="Daily Bitcoin closing price prediction",
|
43 |
+
allow_flagging="never",
|
44 |
+
inputs=[],
|
45 |
+
outputs=[
|
46 |
+
gr.Textbox(label="Date"),
|
47 |
+
gr.Textbox(label="Predicted Closing price"),
|
48 |
+
]
|
49 |
+
)
|
50 |
+
|
51 |
+
demo.launch()
|