vix_spy / app.py
Michelangiolo's picture
bug fix
4570ada
import gradio as gr
import pandas as pd
import numpy as np
import math
import os
os.system('pip install openpyxl')
def vix_calculator(vix, spy, days=365):
score = ( (vix / math.sqrt(days)) / 100 )
return spy*(1-score), spy*(1+score)
# val1, val2 = (vix_spy_csv('VIX.csv'))
# print ('Volatility Range: ' + str(val1) + ' - ' + str(val2))
#multiple inputs are passed as arguments for the same function greet
def greet(file1):
# df = pd.read_csv(file1.name)
if 'csv' in file1.name:
df = pd.read_csv(file1.name, header=None)
df[0] = df[0].apply(lambda x : x.replace(',', ''))
if 'xlsx' in file1.name:
df = pd.read_excel(file1.name, header=None)
df[0] = df[0].apply(lambda x : x.replace(',', ''))
df.index = df.pop(0)
vix_spy_dict = df.to_dict()[1]
print(vix_spy_dict)
output = vix_calculator(vix_spy_dict['VIX'], vix_spy_dict['SPY'], days=365)
print(output)
return str(output)
# iface = gr.Interface(fn=greet, inputs=["file", "file", gr.inputs.Textbox(placeholder="Enter Question here...")], outputs="text")
iface = gr.Interface(fn=greet, inputs=['file'], outputs="text")
# iface.launch(share=True)
iface.launch(share=False)