Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
from nse import *
|
| 4 |
from stock import *
|
| 5 |
-
|
| 6 |
|
| 7 |
# ======================================================
|
| 8 |
# Scrollable HTML wrapper for table output
|
|
@@ -27,7 +26,7 @@ def wrap(html):
|
|
| 27 |
|
| 28 |
|
| 29 |
# ======================================================
|
| 30 |
-
#
|
| 31 |
# ======================================================
|
| 32 |
STOCK_REQ = [
|
| 33 |
"info", "intraday", "daily", "qresult", "result", "balance",
|
|
@@ -41,49 +40,46 @@ INDEX_REQ = [
|
|
| 41 |
|
| 42 |
|
| 43 |
# ======================================================
|
| 44 |
-
#
|
| 45 |
# ======================================================
|
| 46 |
def update_on_mode(mode):
|
| 47 |
if mode == "stock":
|
| 48 |
return (
|
| 49 |
gr.update(choices=STOCK_REQ, value="info", visible=True),
|
| 50 |
-
gr.update(value="ITC")
|
| 51 |
)
|
| 52 |
-
|
| 53 |
elif mode == "index":
|
| 54 |
return (
|
| 55 |
gr.update(choices=INDEX_REQ, value="nse_indices", visible=True),
|
| 56 |
-
gr.update(value="NIFTY 50")
|
| 57 |
)
|
| 58 |
-
|
| 59 |
-
return (
|
| 60 |
-
gr.update(visible=False),
|
| 61 |
-
gr.update(value="")
|
| 62 |
-
)
|
| 63 |
|
| 64 |
|
| 65 |
# ======================================================
|
| 66 |
-
#
|
| 67 |
# ======================================================
|
| 68 |
def fetch_data(mode, req_type, name):
|
| 69 |
req_type = req_type.lower()
|
| 70 |
-
symbol = name
|
| 71 |
|
| 72 |
if mode == "index":
|
| 73 |
if req_type == "nse_indices":
|
| 74 |
return wrap(nse_indices())
|
| 75 |
elif req_type == "nse_open":
|
| 76 |
-
return wrap(nse_open(
|
| 77 |
elif req_type == "nse_preopen":
|
| 78 |
-
return wrap(nse_preopen(
|
| 79 |
elif req_type == "nse_fno":
|
| 80 |
-
return wrap(nse_fno(
|
| 81 |
elif req_type == "nse_future":
|
| 82 |
-
return wrap(nse_future(
|
| 83 |
elif req_type == "nse_bhav":
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
elif req_type == "nse_highlow":
|
| 86 |
-
return wrap(nse_highlow(
|
| 87 |
else:
|
| 88 |
return wrap(f"<h3>No handler for {req_type}</h3>")
|
| 89 |
|
|
@@ -133,7 +129,7 @@ with gr.Blocks(title="Stock / Index App") as iface:
|
|
| 133 |
symbol = gr.Textbox(
|
| 134 |
label="Symbol / Index Name",
|
| 135 |
value="ITC",
|
| 136 |
-
placeholder="Enter symbol",
|
| 137 |
scale=2
|
| 138 |
)
|
| 139 |
|
|
@@ -148,7 +144,7 @@ with gr.Blocks(title="Stock / Index App") as iface:
|
|
| 148 |
|
| 149 |
output = gr.HTML(label="Output")
|
| 150 |
|
| 151 |
-
# Mode changes dropdown + symbol
|
| 152 |
mode_input.change(
|
| 153 |
update_on_mode,
|
| 154 |
inputs=mode_input,
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from nse import *
|
| 3 |
from stock import *
|
| 4 |
+
import pandas as pd
|
| 5 |
|
| 6 |
# ======================================================
|
| 7 |
# Scrollable HTML wrapper for table output
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
# ======================================================
|
| 29 |
+
# Request Type Options
|
| 30 |
# ======================================================
|
| 31 |
STOCK_REQ = [
|
| 32 |
"info", "intraday", "daily", "qresult", "result", "balance",
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
# ======================================================
|
| 43 |
+
# Update Dropdown + Symbol Based on Mode
|
| 44 |
# ======================================================
|
| 45 |
def update_on_mode(mode):
|
| 46 |
if mode == "stock":
|
| 47 |
return (
|
| 48 |
gr.update(choices=STOCK_REQ, value="info", visible=True),
|
| 49 |
+
gr.update(value="ITC", placeholder="Enter stock symbol")
|
| 50 |
)
|
|
|
|
| 51 |
elif mode == "index":
|
| 52 |
return (
|
| 53 |
gr.update(choices=INDEX_REQ, value="nse_indices", visible=True),
|
| 54 |
+
gr.update(value="NIFTY 50", placeholder="Enter index name or date for bhavcopy (DDMMYYYY / DD-MM-YYYY / DD/MM/YYYY)")
|
| 55 |
)
|
| 56 |
+
return (gr.update(visible=False), gr.update(value="", placeholder=""))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
# ======================================================
|
| 60 |
+
# Data Fetcher
|
| 61 |
# ======================================================
|
| 62 |
def fetch_data(mode, req_type, name):
|
| 63 |
req_type = req_type.lower()
|
| 64 |
+
symbol = name.strip()
|
| 65 |
|
| 66 |
if mode == "index":
|
| 67 |
if req_type == "nse_indices":
|
| 68 |
return wrap(nse_indices())
|
| 69 |
elif req_type == "nse_open":
|
| 70 |
+
return wrap(nse_open(symbol))
|
| 71 |
elif req_type == "nse_preopen":
|
| 72 |
+
return wrap(nse_preopen(symbol))
|
| 73 |
elif req_type == "nse_fno":
|
| 74 |
+
return wrap(nse_fno(symbol))
|
| 75 |
elif req_type == "nse_future":
|
| 76 |
+
return wrap(nse_future(symbol))
|
| 77 |
elif req_type == "nse_bhav":
|
| 78 |
+
# If blank, use today
|
| 79 |
+
date_input = symbol or pd.Timestamp.today().strftime("%d-%m-%Y")
|
| 80 |
+
return wrap(nse_bhav(date_input))
|
| 81 |
elif req_type == "nse_highlow":
|
| 82 |
+
return wrap(nse_highlow())
|
| 83 |
else:
|
| 84 |
return wrap(f"<h3>No handler for {req_type}</h3>")
|
| 85 |
|
|
|
|
| 129 |
symbol = gr.Textbox(
|
| 130 |
label="Symbol / Index Name",
|
| 131 |
value="ITC",
|
| 132 |
+
placeholder="Enter stock symbol",
|
| 133 |
scale=2
|
| 134 |
)
|
| 135 |
|
|
|
|
| 144 |
|
| 145 |
output = gr.HTML(label="Output")
|
| 146 |
|
| 147 |
+
# Mode changes dropdown + symbol placeholder
|
| 148 |
mode_input.change(
|
| 149 |
update_on_mode,
|
| 150 |
inputs=mode_input,
|