Spaces:
Runtime error
Runtime error
Michelangiolo
commited on
Commit
•
e57c1e2
1
Parent(s):
34a0abc
first push
Browse files- _test.ipynb +135 -0
- app.py +29 -0
_test.ipynb
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import math\n",
|
10 |
+
"import pandas as pd\n",
|
11 |
+
"\n",
|
12 |
+
"def vix_spy_csv(csv_name):\n",
|
13 |
+
" df = pd.read_csv(csv_name, header=None)\n",
|
14 |
+
" df.index = df.pop(0)\n",
|
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))"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": 7,
|
30 |
+
"metadata": {},
|
31 |
+
"outputs": [
|
32 |
+
{
|
33 |
+
"name": "stdout",
|
34 |
+
"output_type": "stream",
|
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:7865\n",
|
39 |
+
"\n",
|
40 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
41 |
+
]
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"data": {
|
45 |
+
"text/html": [
|
46 |
+
"<div><iframe src=\"http://127.0.0.1:7865/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
47 |
+
],
|
48 |
+
"text/plain": [
|
49 |
+
"<IPython.core.display.HTML object>"
|
50 |
+
]
|
51 |
+
},
|
52 |
+
"metadata": {},
|
53 |
+
"output_type": "display_data"
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"data": {
|
57 |
+
"text/plain": []
|
58 |
+
},
|
59 |
+
"execution_count": 7,
|
60 |
+
"metadata": {},
|
61 |
+
"output_type": "execute_result"
|
62 |
+
},
|
63 |
+
{
|
64 |
+
"name": "stderr",
|
65 |
+
"output_type": "stream",
|
66 |
+
"text": [
|
67 |
+
"Traceback (most recent call last):\n",
|
68 |
+
" File \"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\routes.py\", line 297, in run_predict\n",
|
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 |
+
],
|
86 |
+
"source": [
|
87 |
+
"import gradio as gr\n",
|
88 |
+
"import pandas as pd\n",
|
89 |
+
"import numpy as np\n",
|
90 |
+
"import os\n",
|
91 |
+
"\n",
|
92 |
+
"# os.system('pip install openpyxl')\n",
|
93 |
+
"\n",
|
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 |
+
" output = vix_spy_csv(file1.name)\n",
|
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=\"file\")\n",
|
103 |
+
"# iface.launch(share=True)\n",
|
104 |
+
"iface.launch(share=False)"
|
105 |
+
]
|
106 |
+
}
|
107 |
+
],
|
108 |
+
"metadata": {
|
109 |
+
"kernelspec": {
|
110 |
+
"display_name": "Python 3",
|
111 |
+
"language": "python",
|
112 |
+
"name": "python3"
|
113 |
+
},
|
114 |
+
"language_info": {
|
115 |
+
"codemirror_mode": {
|
116 |
+
"name": "ipython",
|
117 |
+
"version": 3
|
118 |
+
},
|
119 |
+
"file_extension": ".py",
|
120 |
+
"mimetype": "text/x-python",
|
121 |
+
"name": "python",
|
122 |
+
"nbconvert_exporter": "python",
|
123 |
+
"pygments_lexer": "ipython3",
|
124 |
+
"version": "3.9.13"
|
125 |
+
},
|
126 |
+
"orig_nbformat": 4,
|
127 |
+
"vscode": {
|
128 |
+
"interpreter": {
|
129 |
+
"hash": "fdf377d643bc1cb065454f0ad2ceac75d834452ecf289e7ba92c6b3f59a7cee1"
|
130 |
+
}
|
131 |
+
}
|
132 |
+
},
|
133 |
+
"nbformat": 4,
|
134 |
+
"nbformat_minor": 2
|
135 |
+
}
|
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
import math
|
6 |
+
os.system('pip install openpyxl')
|
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 |
+
def vix_calculator(vix, spy, days=365):
|
14 |
+
score = ( (vix / math.sqrt(days)) / 100 )
|
15 |
+
return spy*(1-score), spy*(1+score)
|
16 |
+
|
17 |
+
return vix_calculator(vix_spy_dict['VIX'], vix_spy_dict['SPY'], days=365)
|
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 |
+
output = vix_spy_csv(file1.name)
|
23 |
+
print(output)
|
24 |
+
return str(output)
|
25 |
+
|
26 |
+
# iface = gr.Interface(fn=greet, inputs=["file", "file", gr.inputs.Textbox(placeholder="Enter Question here...")], outputs="text")
|
27 |
+
iface = gr.Interface(fn=greet, inputs=['file'], outputs="text")
|
28 |
+
# iface.launch(share=True)
|
29 |
+
iface.launch(share=False)
|