backend / app.py
eshan6704's picture
Update app.py
bc71b9f verified
raw
history blame
2.59 kB
import gradio as gr
from daily import fetch_daily
from intraday import fetch_intraday
from info import fetch_info
from qresult import fetch_qresult
from result import fetch_result
from balance import fetch_balance
from cashflow import fetch_cashflow
from dividend import fetch_dividend
from split import fetch_split
from other import fetch_other
from index import fetch_index
# -----------------------------
# Data fetch function
# -----------------------------
def fetch_data(mode, req_type, name):
req_type = req_type.lower()
symbol = name
if req_type == "index":
return fetch_index()
elif req_type == "daily":
return fetch_daily(symbol, "NSE")
elif req_type == "intraday":
return fetch_intraday(symbol)
elif req_type == "info":
return fetch_info(symbol)
elif req_type == "qresult":
return fetch_qresult(symbol)
elif req_type == "result":
return fetch_result(symbol)
elif req_type == "balance":
return fetch_balance(symbol)
elif req_type == "cashflow":
return fetch_cashflow(symbol)
elif req_type == "dividend":
return fetch_dividend(symbol)
elif req_type == "split":
return fetch_split(symbol)
elif req_type == "other":
return fetch_other(symbol)
else:
return f"<h1>No handler for {req_type}</h1>"
# -----------------------------
# UI
# -----------------------------
with gr.Blocks(title="Stock / Index App") as iface:
gr.Markdown("### **Stock / Index Data Fetcher**")
# ----- Top bar -----
with gr.Row():
mode_input = gr.Textbox(
label="Mode",
value="stock",
placeholder="stock / index",
scale=1
)
symbol = gr.Textbox(
label="Symbol / Index Name",
value="PNB",
placeholder="Enter symbol",
scale=2
)
req_type = gr.Dropdown(
label="Request Type",
choices=[
"info","intraday","daily","qresult","result","balance","cashflow",
"dividend","split","index","open","preopen","ce","pe","future","bhav","highlow"
],
value="info",
scale=2
)
btn = gr.Button("Fetch", scale=1)
# ----- Output -----
output = gr.HTML(label="Output")
btn.click(fetch_data, inputs=[mode_input, req_type, symbol], outputs=output)
# -----------------------------
# Launch
# -----------------------------
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)