Spaces:
Sleeping
Sleeping
New
Browse files
app.py
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import yfinance as yf
|
| 5 |
+
from prophet import Prophet
|
| 6 |
+
from prophet.plot import plot_plotly, plot_components_plotly
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
import warnings
|
| 10 |
+
warnings.simplefilter(action='ignore', category=FutureWarning)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
stocks = pd.read_excel('Stocks.xlsx', usecols =[1,2,3])
|
| 14 |
+
|
| 15 |
+
period_options = {
|
| 16 |
+
"1wk": "1 Week",
|
| 17 |
+
"1mo": "1 Month",
|
| 18 |
+
"1y": "1 Year",
|
| 19 |
+
"5y": "5 Years"
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Create a Gradio radio button group for the period
|
| 24 |
+
period = gr.Radio(label="Training Period: ", choices=list(period_options.values()), value="1 Week")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Define the function to return the symbol corresponding to the selected company name
|
| 28 |
+
def get_forecast(company_name):
|
| 29 |
+
symbol_nse = stocks[stocks['Company Name'] == company_name]['Symbol'].values[0] + '.NS'
|
| 30 |
+
#period_key = [key for key, value in period_options.items() if value == period][0]
|
| 31 |
+
#stock_df = yf.download(symbol_nse, period = period_key)
|
| 32 |
+
|
| 33 |
+
stock_df = yf.download(symbol_nse, period = '5y')
|
| 34 |
+
stock_df.drop(stock_df.columns[[0,1,2,4,5]], axis=1, inplace=True)
|
| 35 |
+
stock_df.reset_index(inplace=True)
|
| 36 |
+
stock_df.columns = ['ds', 'y']
|
| 37 |
+
#stock_df = stock_df[['ds', 'y', 'cap']]
|
| 38 |
+
|
| 39 |
+
#model = Prophet(growth='logistic')
|
| 40 |
+
model = Prophet()
|
| 41 |
+
model.fit(stock_df)
|
| 42 |
+
|
| 43 |
+
future = model.make_future_dataframe(periods = 7)
|
| 44 |
+
forecast = model.predict(future)
|
| 45 |
+
forecast_df = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
|
| 46 |
+
|
| 47 |
+
fig = plot_plotly(model, forecast_df)
|
| 48 |
+
fig.update_layout(xaxis_title="Date", yaxis_title="Price")
|
| 49 |
+
|
| 50 |
+
return fig
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
with gr.Blocks() as demo:
|
| 54 |
+
|
| 55 |
+
gr.Markdown(
|
| 56 |
+
"""
|
| 57 |
+
# NSE Stock Price Trend Prediction
|
| 58 |
+
Select the Stock from Dropdown Menu to get next week Prediction
|
| 59 |
+
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
)
|
| 63 |
+
with gr.Row():
|
| 64 |
+
dropdown = gr.Dropdown(label="Company Name", choices=stocks['Company Name'].tolist(), filterable = True, info = 'Select NSE Stock')
|
| 65 |
+
|
| 66 |
+
with gr.Row():
|
| 67 |
+
with gr.Column():
|
| 68 |
+
None
|
| 69 |
+
with gr.Column():
|
| 70 |
+
None
|
| 71 |
+
with gr.Column():
|
| 72 |
+
None
|
| 73 |
+
with gr.Column():
|
| 74 |
+
submit_btn = gr.Button(value = "Predict")
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
forecast_plot = gr.Plot(label = 'Forecast Plot')
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
submit_btn.click(get_forecast, inputs=dropdown, outputs=forecast_plot)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
demo.launch(share=True, debug=True)
|