Spaces:
Runtime error
Runtime error
Michelangiolo
commited on
Commit
•
c5213f7
1
Parent(s):
e57c1e2
v2
Browse files
VIX.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
SPY,407.20
|
2 |
+
VIX,20.02
|
VIX.xlsx
ADDED
Binary file (8.84 kB). View file
|
|
_test.ipynb
CHANGED
@@ -2,23 +2,16 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import math\n",
|
10 |
"import pandas as pd\n",
|
11 |
"\n",
|
12 |
-
"def
|
13 |
-
"
|
14 |
-
"
|
15 |
-
" vix_spy_dict = df.to_dict()[1]\n",
|
16 |
-
"\n",
|
17 |
-
" def vix_calculator(vix, spy, days=365):\n",
|
18 |
-
" score = ( (vix / math.sqrt(days)) / 100 )\n",
|
19 |
-
" return spy*(1-score), spy*(1+score)\n",
|
20 |
-
"\n",
|
21 |
-
" return vix_calculator(vix_spy_dict['VIX'], vix_spy_dict['SPY'], days=365)\n",
|
22 |
"\n",
|
23 |
"# val1, val2 = (vix_spy_csv('VIX.csv'))\n",
|
24 |
"# print ('Volatility Range: ' + str(val1) + ' - ' + str(val2))"
|
@@ -26,7 +19,128 @@
|
|
26 |
},
|
27 |
{
|
28 |
"cell_type": "code",
|
29 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
"metadata": {},
|
31 |
"outputs": [
|
32 |
{
|
@@ -35,7 +149,7 @@
|
|
35 |
"text": [
|
36 |
"IMPORTANT: You are using gradio version 3.13.0, however version 3.14.0 is available, please upgrade.\n",
|
37 |
"--------\n",
|
38 |
-
"Running on local URL: http://127.0.0.1:
|
39 |
"\n",
|
40 |
"To create a public link, set `share=True` in `launch()`.\n"
|
41 |
]
|
@@ -43,7 +157,7 @@
|
|
43 |
{
|
44 |
"data": {
|
45 |
"text/html": [
|
46 |
-
"<div><iframe src=\"http://127.0.0.1:
|
47 |
],
|
48 |
"text/plain": [
|
49 |
"<IPython.core.display.HTML object>"
|
@@ -56,30 +170,16 @@
|
|
56 |
"data": {
|
57 |
"text/plain": []
|
58 |
},
|
59 |
-
"execution_count":
|
60 |
"metadata": {},
|
61 |
"output_type": "execute_result"
|
62 |
},
|
63 |
{
|
64 |
-
"name": "
|
65 |
"output_type": "stream",
|
66 |
"text": [
|
67 |
-
"
|
68 |
-
"
|
69 |
-
" output = await app.blocks.process_api(\n",
|
70 |
-
" File \"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\blocks.py\", line 1007, in process_api\n",
|
71 |
-
" result = await self.call_function(fn_index, inputs, iterator, request)\n",
|
72 |
-
" File \"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\blocks.py\", line 848, in call_function\n",
|
73 |
-
" prediction = await anyio.to_thread.run_sync(\n",
|
74 |
-
" File \"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\anyio\\to_thread.py\", line 31, in run_sync\n",
|
75 |
-
" return await get_asynclib().run_sync_in_worker_thread(\n",
|
76 |
-
" File \"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 937, in run_sync_in_worker_thread\n",
|
77 |
-
" return await future\n",
|
78 |
-
" File \"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 867, in run\n",
|
79 |
-
" result = context.run(func, *args)\n",
|
80 |
-
" File \"C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_616\\2025908543.py\", line 11, in greet\n",
|
81 |
-
" output = vix_spy_csv(file1.name)\n",
|
82 |
-
"NameError: name 'vix_spy_csv' is not defined\n"
|
83 |
]
|
84 |
}
|
85 |
],
|
@@ -94,12 +194,26 @@
|
|
94 |
"#multiple inputs are passed as arguments for the same function greet\n",
|
95 |
"def greet(file1):\n",
|
96 |
" # df = pd.read_csv(file1.name)\n",
|
97 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
" print(output)\n",
|
99 |
" return str(output)\n",
|
100 |
"\n",
|
101 |
"# iface = gr.Interface(fn=greet, inputs=[\"file\", \"file\", gr.inputs.Textbox(placeholder=\"Enter Question here...\")], outputs=\"text\")\n",
|
102 |
-
"iface = gr.Interface(fn=greet, inputs=['file'], outputs=\"
|
103 |
"# iface.launch(share=True)\n",
|
104 |
"iface.launch(share=False)"
|
105 |
]
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 13,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import math\n",
|
10 |
"import pandas as pd\n",
|
11 |
"\n",
|
12 |
+
"def vix_calculator(vix, spy, days=365):\n",
|
13 |
+
" score = ( (vix / math.sqrt(days)) / 100 )\n",
|
14 |
+
" return spy*(1-score), spy*(1+score)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
"\n",
|
16 |
"# val1, val2 = (vix_spy_csv('VIX.csv'))\n",
|
17 |
"# print ('Volatility Range: ' + str(val1) + ' - ' + str(val2))"
|
|
|
19 |
},
|
20 |
{
|
21 |
"cell_type": "code",
|
22 |
+
"execution_count": 19,
|
23 |
+
"metadata": {},
|
24 |
+
"outputs": [
|
25 |
+
{
|
26 |
+
"data": {
|
27 |
+
"text/html": [
|
28 |
+
"<div>\n",
|
29 |
+
"<style scoped>\n",
|
30 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
31 |
+
" vertical-align: middle;\n",
|
32 |
+
" }\n",
|
33 |
+
"\n",
|
34 |
+
" .dataframe tbody tr th {\n",
|
35 |
+
" vertical-align: top;\n",
|
36 |
+
" }\n",
|
37 |
+
"\n",
|
38 |
+
" .dataframe thead th {\n",
|
39 |
+
" text-align: right;\n",
|
40 |
+
" }\n",
|
41 |
+
"</style>\n",
|
42 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
43 |
+
" <thead>\n",
|
44 |
+
" <tr style=\"text-align: right;\">\n",
|
45 |
+
" <th></th>\n",
|
46 |
+
" <th>0</th>\n",
|
47 |
+
" <th>1</th>\n",
|
48 |
+
" </tr>\n",
|
49 |
+
" </thead>\n",
|
50 |
+
" <tbody>\n",
|
51 |
+
" <tr>\n",
|
52 |
+
" <th>0</th>\n",
|
53 |
+
" <td>SPY</td>\n",
|
54 |
+
" <td>407.20</td>\n",
|
55 |
+
" </tr>\n",
|
56 |
+
" <tr>\n",
|
57 |
+
" <th>1</th>\n",
|
58 |
+
" <td>VIX</td>\n",
|
59 |
+
" <td>20.02</td>\n",
|
60 |
+
" </tr>\n",
|
61 |
+
" </tbody>\n",
|
62 |
+
"</table>\n",
|
63 |
+
"</div>"
|
64 |
+
],
|
65 |
+
"text/plain": [
|
66 |
+
" 0 1\n",
|
67 |
+
"0 SPY 407.20\n",
|
68 |
+
"1 VIX 20.02"
|
69 |
+
]
|
70 |
+
},
|
71 |
+
"execution_count": 19,
|
72 |
+
"metadata": {},
|
73 |
+
"output_type": "execute_result"
|
74 |
+
}
|
75 |
+
],
|
76 |
+
"source": [
|
77 |
+
"pd.read_csv('VIX.csv', header=None)"
|
78 |
+
]
|
79 |
+
},
|
80 |
+
{
|
81 |
+
"cell_type": "code",
|
82 |
+
"execution_count": 22,
|
83 |
+
"metadata": {},
|
84 |
+
"outputs": [
|
85 |
+
{
|
86 |
+
"data": {
|
87 |
+
"text/html": [
|
88 |
+
"<div>\n",
|
89 |
+
"<style scoped>\n",
|
90 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
91 |
+
" vertical-align: middle;\n",
|
92 |
+
" }\n",
|
93 |
+
"\n",
|
94 |
+
" .dataframe tbody tr th {\n",
|
95 |
+
" vertical-align: top;\n",
|
96 |
+
" }\n",
|
97 |
+
"\n",
|
98 |
+
" .dataframe thead th {\n",
|
99 |
+
" text-align: right;\n",
|
100 |
+
" }\n",
|
101 |
+
"</style>\n",
|
102 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
103 |
+
" <thead>\n",
|
104 |
+
" <tr style=\"text-align: right;\">\n",
|
105 |
+
" <th></th>\n",
|
106 |
+
" <th>0</th>\n",
|
107 |
+
" <th>1</th>\n",
|
108 |
+
" </tr>\n",
|
109 |
+
" </thead>\n",
|
110 |
+
" <tbody>\n",
|
111 |
+
" <tr>\n",
|
112 |
+
" <th>0</th>\n",
|
113 |
+
" <td>SPY</td>\n",
|
114 |
+
" <td>399.07</td>\n",
|
115 |
+
" </tr>\n",
|
116 |
+
" <tr>\n",
|
117 |
+
" <th>1</th>\n",
|
118 |
+
" <td>VIX</td>\n",
|
119 |
+
" <td>22.70</td>\n",
|
120 |
+
" </tr>\n",
|
121 |
+
" </tbody>\n",
|
122 |
+
"</table>\n",
|
123 |
+
"</div>"
|
124 |
+
],
|
125 |
+
"text/plain": [
|
126 |
+
" 0 1\n",
|
127 |
+
"0 SPY 399.07\n",
|
128 |
+
"1 VIX 22.70"
|
129 |
+
]
|
130 |
+
},
|
131 |
+
"execution_count": 22,
|
132 |
+
"metadata": {},
|
133 |
+
"output_type": "execute_result"
|
134 |
+
}
|
135 |
+
],
|
136 |
+
"source": [
|
137 |
+
"df = pd.read_excel('VIX.xlsx', header=None)\n",
|
138 |
+
"df"
|
139 |
+
]
|
140 |
+
},
|
141 |
+
{
|
142 |
+
"cell_type": "code",
|
143 |
+
"execution_count": 23,
|
144 |
"metadata": {},
|
145 |
"outputs": [
|
146 |
{
|
|
|
149 |
"text": [
|
150 |
"IMPORTANT: You are using gradio version 3.13.0, however version 3.14.0 is available, please upgrade.\n",
|
151 |
"--------\n",
|
152 |
+
"Running on local URL: http://127.0.0.1:7873\n",
|
153 |
"\n",
|
154 |
"To create a public link, set `share=True` in `launch()`.\n"
|
155 |
]
|
|
|
157 |
{
|
158 |
"data": {
|
159 |
"text/html": [
|
160 |
+
"<div><iframe src=\"http://127.0.0.1:7873/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
161 |
],
|
162 |
"text/plain": [
|
163 |
"<IPython.core.display.HTML object>"
|
|
|
170 |
"data": {
|
171 |
"text/plain": []
|
172 |
},
|
173 |
+
"execution_count": 23,
|
174 |
"metadata": {},
|
175 |
"output_type": "execute_result"
|
176 |
},
|
177 |
{
|
178 |
+
"name": "stdout",
|
179 |
"output_type": "stream",
|
180 |
"text": [
|
181 |
+
"{'SPY': 399.07, 'VIX': 22.7}\n",
|
182 |
+
"(394.3283607853106, 403.81163921468936)\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
]
|
184 |
}
|
185 |
],
|
|
|
194 |
"#multiple inputs are passed as arguments for the same function greet\n",
|
195 |
"def greet(file1):\n",
|
196 |
" # df = pd.read_csv(file1.name)\n",
|
197 |
+
" if 'csv' in file1.name:\n",
|
198 |
+
" df = pd.read_csv(file1.name, header=None)\n",
|
199 |
+
" df[0] = df[0].apply(lambda x : x.replace(',', ''))\n",
|
200 |
+
"\n",
|
201 |
+
" if 'xlsx' in file1.name:\n",
|
202 |
+
" df = pd.read_excel(file1.name, header=None)\n",
|
203 |
+
" df[0] = df[0].apply(lambda x : x.replace(',', ''))\n",
|
204 |
+
"\n",
|
205 |
+
" df.index = df.pop(0)\n",
|
206 |
+
" vix_spy_dict = df.to_dict()[1]\n",
|
207 |
+
"\n",
|
208 |
+
" print(vix_spy_dict)\n",
|
209 |
+
"\n",
|
210 |
+
" output = vix_calculator(vix_spy_dict['VIX'], vix_spy_dict['SPY'], days=365)\n",
|
211 |
+
"\n",
|
212 |
" print(output)\n",
|
213 |
" return str(output)\n",
|
214 |
"\n",
|
215 |
"# iface = gr.Interface(fn=greet, inputs=[\"file\", \"file\", gr.inputs.Textbox(placeholder=\"Enter Question here...\")], outputs=\"text\")\n",
|
216 |
+
"iface = gr.Interface(fn=greet, inputs=['file'], outputs=\"text\")\n",
|
217 |
"# iface.launch(share=True)\n",
|
218 |
"iface.launch(share=False)"
|
219 |
]
|
app.py
CHANGED
@@ -1,25 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
import os
|
5 |
import math
|
6 |
-
os
|
7 |
-
|
8 |
-
def vix_spy_csv(csv_name):
|
9 |
-
df = pd.read_csv(csv_name, header=None)
|
10 |
-
df.index = df.pop(0)
|
11 |
-
vix_spy_dict = df.to_dict()[1]
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
|
|
18 |
|
19 |
#multiple inputs are passed as arguments for the same function greet
|
20 |
def greet(file1):
|
21 |
# df = pd.read_csv(file1.name)
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
print(output)
|
24 |
return str(output)
|
25 |
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
|
|
4 |
import math
|
5 |
+
import os
|
6 |
+
# os.system('pip install openpyxl')
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def vix_calculator(vix, spy, days=365):
|
9 |
+
score = ( (vix / math.sqrt(days)) / 100 )
|
10 |
+
return spy*(1-score), spy*(1+score)
|
11 |
|
12 |
+
# val1, val2 = (vix_spy_csv('VIX.csv'))
|
13 |
+
# print ('Volatility Range: ' + str(val1) + ' - ' + str(val2))
|
14 |
|
15 |
#multiple inputs are passed as arguments for the same function greet
|
16 |
def greet(file1):
|
17 |
# df = pd.read_csv(file1.name)
|
18 |
+
if 'csv' in file1.name:
|
19 |
+
df = pd.read_csv(file1.name, header=None)
|
20 |
+
df[0] = df[0].apply(lambda x : x.replace(',', ''))
|
21 |
+
|
22 |
+
if 'xlsx' in file1.name:
|
23 |
+
df = pd.read_excel(file1.name, header=None)
|
24 |
+
df[0] = df[0].apply(lambda x : x.replace(',', ''))
|
25 |
+
|
26 |
+
df.index = df.pop(0)
|
27 |
+
vix_spy_dict = df.to_dict()[1]
|
28 |
+
|
29 |
+
print(vix_spy_dict)
|
30 |
+
|
31 |
+
output = vix_calculator(vix_spy_dict['VIX'], vix_spy_dict['SPY'], days=365)
|
32 |
+
|
33 |
print(output)
|
34 |
return str(output)
|
35 |
|