eshan6704 commited on
Commit
b2ed551
·
verified ·
1 Parent(s): 2ea612e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -17
app.py CHANGED
@@ -1,5 +1,6 @@
1
  # app.py
2
  import gradio as gr
 
3
  from daily import fetch_daily
4
  from intraday import fetch_intraday
5
  from info import fetch_info
@@ -11,13 +12,15 @@ from dividend import fetch_dividend
11
  from split import fetch_split
12
  from other import fetch_other
13
  from index import fetch_index
 
 
14
  # --- Main UI function ---
15
  def fetch_data(symbol, req_type):
16
  req_type = req_type.lower()
17
  if req_type == "index":
18
- return fetch_index()
19
  elif req_type == "daily":
20
- return fetch_daily(symbol,"NSE")
21
  elif req_type == "intraday":
22
  return fetch_intraday(symbol)
23
  elif req_type == "info":
@@ -39,13 +42,23 @@ def fetch_data(symbol, req_type):
39
  else:
40
  return f"<h1>No handler for {req_type}</h1>"
41
 
42
- # --- Gradio Interface ---
43
- iface = gr.Interface(
44
- fn=fetch_data,
45
- inputs=[
46
- gr.Textbox(label="Stock Symbol", value="PNB"),
47
- gr.Dropdown(
48
- label="Request Type",
 
 
 
 
 
 
 
 
 
 
49
  choices=[
50
  "index",
51
  "info",
@@ -59,14 +72,22 @@ iface = gr.Interface(
59
  "split",
60
  "other"
61
  ],
62
- value="info"
 
63
  )
64
- ],
65
- outputs=gr.HTML(label="Full HTML Output"),
66
- title="Stock Data API (Full)",
67
- description="Fetch NSE stock data with charts and indicators",
68
- api_name="fetch_data"
69
- )
 
 
 
 
 
 
70
 
 
71
  if __name__ == "__main__":
72
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  # app.py
2
  import gradio as gr
3
+
4
  from daily import fetch_daily
5
  from intraday import fetch_intraday
6
  from info import fetch_info
 
12
  from split import fetch_split
13
  from other import fetch_other
14
  from index import fetch_index
15
+
16
+
17
  # --- Main UI function ---
18
  def fetch_data(symbol, req_type):
19
  req_type = req_type.lower()
20
  if req_type == "index":
21
+ return fetch_index()
22
  elif req_type == "daily":
23
+ return fetch_daily(symbol, "NSE")
24
  elif req_type == "intraday":
25
  return fetch_intraday(symbol)
26
  elif req_type == "info":
 
42
  else:
43
  return f"<h1>No handler for {req_type}</h1>"
44
 
45
+
46
+ # --- Gradio Minimal Layout ---
47
+ with gr.Blocks(css="""
48
+ .gradio-container {padding-top: 0 !important;}
49
+ #topbar {margin: 0; padding: 0;}
50
+ """) as iface:
51
+
52
+ # Top horizontal row
53
+ with gr.Row(elem_id="topbar"):
54
+ symbol = gr.Textbox(
55
+ label="",
56
+ placeholder="Enter Symbol (e.g., PNB)",
57
+ value="PNB",
58
+ scale=2
59
+ )
60
+ req_type = gr.Dropdown(
61
+ label="",
62
  choices=[
63
  "index",
64
  "info",
 
72
  "split",
73
  "other"
74
  ],
75
+ value="info",
76
+ scale=2
77
  )
78
+ btn = gr.Button("Submit", scale=1)
79
+
80
+ # Output container (full HTML)
81
+ output = gr.HTML()
82
+
83
+ # Bind click event
84
+ btn.click(
85
+ fetch_data,
86
+ inputs=[symbol, req_type],
87
+ outputs=output
88
+ )
89
+
90
 
91
+ # --- Launch Server ---
92
  if __name__ == "__main__":
93
+ iface.launch(server_name="0.0.0.0", server_port=7860)