demo-visualizer / app.py
jaygodara45's picture
Update app.py
aac3844 verified
import gradio as gr
# importing necessary libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from datetime import datetime
from pandas import Series
df = pd.read_csv("./MARUTI.csv")
data = df[['Date','Open','High','Low','Close','Volume','VWAP']]
data['Date'] = data['Date'].apply(pd.to_datetime)
df_vwap = df[['Date','VWAP']]
df_vwap['Date'] = df_vwap['Date'].apply(pd.to_datetime)
df_vwap['year'] = df_vwap.Date.dt.year
df_vwap['month'] = df_vwap.Date.dt.month
df_vwap['day'] = df_vwap.Date.dt.day
df_vwap['day of week'] = df_vwap.Date.dt.dayofweek
df_vwap.set_index('Date', inplace=True)
# fig = plt.figure()
def yearSeriesPlot():
fig = plt.figure(figsize=(16,8))
plt.plot(df_vwap['VWAP'], label='VWAP')
plt.title('Time Series')
plt.xlabel("Time(year)")
plt.ylabel("Volume Weighted Average Price")
plt.legend(loc='best')
return fig
# yearly variation histogram
def yearHistogramPlot():
fig = plt.figure(figsize=(16, 8))
df_vwap.groupby('year')['VWAP'].mean().plot.bar()
return fig
# monthly variations
def monthHistogramPlot():
fig = plt.figure(figsize=(16, 8))
df_vwap.groupby('month')['VWAP'].mean().plot.bar()
return fig
#daily variations
def dailyHistogramPlot():
fig = plt.figure(figsize=(16, 8))
df_vwap.groupby('day')['VWAP'].mean().plot.bar()
return fig
def weekDayHistogramPlot():
fig = plt.figure(figsize=(16, 8))
df_vwap.groupby('day of week')['VWAP'].mean().plot.bar()
return fig
def vwapSeriesPlot():
fig = plt.figure(figsize=(16, 8))
df_vwap['VWAP'].plot(figsize = (10,6))
return fig
def plotGraph(plot_type):
if plot_type=="yearSeriesPlot":
return yearSeriesPlot()
elif plot_type=="yearHistogramPlot":
return yearHistogramPlot()
elif plot_type=="monthHistogramPlot":
return monthHistogramPlot()
elif plot_type=="dailyHistogramPlot":
return dailyHistogramPlot()
elif plot_type=="weekDayHistogramPlot":
return weekDayHistogramPlot()
elif plot_type=="vwapSeriesPlot":
return vwapSeriesPlot()
else:
raise ValueError("select valid plot")
inputs = [
gr.Dropdown(["yearSeriesPlot", "yearHistogramPlot", "monthHistogramPlot", "dailyHistogramPlot", "weekDayHistogramPlot", "vwapSeriesPlot"], label="Select type of plot")
]
outputs = gr.Plot()
demo = gr.Interface(
fn=plotGraph,
inputs=inputs,
outputs=outputs,
)
demo.launch()