File size: 2,361 Bytes
df112e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
from neuralprophet import NeuralProphet, set_log_level
import warnings

set_log_level("ERROR")
warnings.filterwarnings("ignore", category=UserWarning)

url = "Bitcoin Historical Data - Investing.com.csv"
df = pd.read_csv(url)
df = df[["Date", "Price"]]
df = df.rename(columns={"Date": "ds", "Price": "y"})
df.fillna(method='ffill', inplace=True)
df.dropna(inplace=True)

m = NeuralProphet(n_forecasts=3,
    n_lags=36, 
    changepoints_range=1, num_hidden_layers=6, daily_seasonality= False, weekly_seasonality = False, yearly_seasonality = True, ar_reg=True,
    n_changepoints=100, trend_reg_threshold=True, d_hidden=9, global_normalization=True, global_time_normalization=True, seasonality_reg=1, unknown_data_normalization=True,
    seasonality_mode="multiplicative", drop_missing=True,
    learning_rate=0.0314
)

m.fit(df, freq='M')

future = m.make_future_dataframe(df, periods=3, n_historic_predictions=True)
forecast = m.predict(future)

def predict_vn_index(option=None):
    fig1 = m.plot(forecast)
    fig1_path = "forecast_plot1.png"
    fig1.savefig(fig1_path)

    # Add code to generate the second image (fig2)
    fig2 = m.plot_latest_forecast(forecast)  # Replace this line with code to generate the second image
    fig2_path = "forecast_plot2.png"
    fig2.savefig(fig2_path)
    description = "Dự đoán được thực hiện bởi thuật toán AI học sâu (Deep Learning), và học tăng cường dữ liệu bởi đội ngũ AI Consultant. Dữ liệu được cập nhật mới sau 17h của ngày giao dịch."
    disclaimer = "Quý khách chỉ xem đây là tham khảo, công ty không chịu bất cứ trách nhiệm nào về tình trạng đầu tư của quý khách."
    

    return fig1_path, fig2_path, description, disclaimer


if __name__ == "__main__":
    dropdown = gr.inputs.Dropdown(["BTC"], label="Choose an option", default="BTC")
    outputs = [
        gr.outputs.Image(type="filepath", label="Lịch sử BTC và dự đoán"),
        gr.outputs.Image(type="filepath", label="Dự đoán BTC cho 90 ngày tới"),
        gr.outputs.Textbox(label="Mô tả"),
        gr.outputs.Textbox(label="Disclaimer")
    ]
    interface = gr.Interface(fn=predict_vn_index, inputs=dropdown, outputs=outputs, title="Dự báo BTC 90 ngày tới")
    interface.launch()