omniverse1 commited on
Commit
972a547
·
verified ·
1 Parent(s): 9b9ec8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -42
app.py CHANGED
@@ -14,6 +14,7 @@ import warnings
14
 
15
  warnings.filterwarnings("ignore")
16
 
 
17
  def analyze_stock(symbol, prediction_days=30):
18
  try:
19
  if not symbol.strip():
@@ -32,19 +33,25 @@ def analyze_stock(symbol, prediction_days=30):
32
  signals = generate_trading_signals(data, indicators)
33
  fundamental_info = get_fundamental_data(stock)
34
  predictions = predict_prices(data, prediction_days=prediction_days)
 
35
  fig_price = create_price_chart(data, indicators)
36
  fig_technical = create_technical_chart(data, indicators)
37
  fig_prediction = create_prediction_chart(data, predictions)
38
 
39
  return fundamental_info, indicators, signals, fig_price, fig_technical, fig_prediction, predictions
 
40
  except Exception as e:
41
  print(f"Error analyzing {symbol}: {e}")
42
  empty_fig = gr.Plot.update(value=None)
43
  empty_predictions = {
44
- 'high_30d': 0, 'low_30d': 0, 'change_pct': 0, 'summary': 'Prediction unavailable.'
 
 
 
45
  }
46
  return {}, {}, {}, empty_fig, empty_fig, empty_fig, empty_predictions
47
 
 
48
  def update_analysis(symbol, prediction_days):
49
  (
50
  fundamental_info,
@@ -58,16 +65,20 @@ def update_analysis(symbol, prediction_days):
58
 
59
  if not fundamental_info:
60
  return (
61
- "Unable to fetch stock data.",
 
62
  gr.Plot.update(value=None),
63
  gr.Plot.update(value=None),
64
  gr.Plot.update(value=None),
65
- "",
66
- "0", "0", "0", ""
 
 
67
  )
68
 
69
  fundamentals = f"""
70
- ### 🏢 {fundamental_info.get('name', 'N/A')} ({symbol.upper()})
 
71
  **Current Price:** Rp{fundamental_info.get('current_price', 0):,.2f}
72
  **Market Cap:** {fundamental_info.get('market_cap', 0):,}
73
  **P/E Ratio:** {fundamental_info.get('pe_ratio', 0):.2f}
@@ -76,24 +87,24 @@ def update_analysis(symbol, prediction_days):
76
  """
77
 
78
  trading_signal = f"""
79
- ### 📊 Technical Signal Summary
80
  **Overall Trend:** {signals.get('overall', 'N/A')}
81
  **Signal Strength:** {signals.get('strength', 0):.2f}%
82
- **Support:** {signals.get('support', 0):,.2f}
83
- **Resistance:** {signals.get('resistance', 0):,.2f}
84
- **Stop Loss:** {signals.get('stop_loss', 0):,.2f}
85
 
86
- **Detailed Insights:**
87
  {signals.get('details', '')}
88
  """
89
 
90
  prediction = f"""
91
- ### 🤖 30-Day AI Forecast (Amazon Chronos-Bolt)
92
  **Predicted High:** Rp{predictions.get('high_30d', 0):,.2f}
93
  **Predicted Low:** Rp{predictions.get('low_30d', 0):,.2f}
94
  **Expected Change:** {predictions.get('change_pct', 0):.2f}%
95
 
96
- 🧠 **Model Insight:**
97
  {predictions.get('summary', 'No analysis available')}
98
  """
99
 
@@ -109,41 +120,76 @@ def update_analysis(symbol, prediction_days):
109
  prediction,
110
  )
111
 
 
112
  with gr.Blocks(
113
- title="RexPro Financial AI Dashboard",
114
- theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="emerald"),
115
  css="""
116
- body {background-color: #0f172a; color: #e2e8f0; font-family: 'Inter', sans-serif;}
117
- h1, h2, h3 {color: #22d3ee;}
118
- .gr-markdown {background-color: #1e293b; border-radius: 12px; padding: 18px; color: #e2e8f0;}
119
- .gr-button {background: linear-gradient(90deg, #06b6d4, #14b8a6); color: white !important; font-weight: 600; border-radius: 10px;}
120
- .gr-textbox label, .gr-slider label {color: #a5f3fc;}
121
- .gr-textbox input, .gr-slider {background-color: #1e293b; color: white;}
122
- .gr-plot {background-color: #1e293b; border-radius: 12px;}
123
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ) as app:
125
- gr.Markdown("# 💹 REXPRO FINANCIAL AI DASHBOARD")
126
- gr.Markdown("Smart market insights powered by **Chronos-Bolt AI** — for serious investors and analysts.", elem_id="subheader")
 
 
127
 
128
- with gr.Row(equal_height=True):
129
  symbol = gr.Textbox(
130
- label="Stock Symbol (IDX)",
131
  value="BBCA",
132
- placeholder="Example: BBCA, TLKM, ADRO, BMRI ...",
133
  interactive=True,
134
- lines=1,
135
  )
136
  prediction_days = gr.Slider(
137
- label="Forecast Period (Days)",
138
  minimum=5,
139
  maximum=60,
140
  step=5,
141
  value=30,
142
  interactive=True,
143
  )
144
- analyze_button = gr.Button("🚀 Run Analysis")
145
 
146
- gr.Markdown("---")
147
 
148
  with gr.Row():
149
  with gr.Column(scale=1):
@@ -151,21 +197,21 @@ with gr.Blocks(
151
  with gr.Column(scale=1):
152
  signal_output = gr.Markdown()
153
 
154
- gr.Markdown("---")
155
 
156
- with gr.Tab("📈 Market Charts"):
157
  with gr.Row():
158
- price_chart = gr.Plot(label="Price & Moving Averages")
159
- technical_chart = gr.Plot(label="Technical Indicators Overview")
160
- gr.Markdown("---")
161
- prediction_chart = gr.Plot(label="AI Forecast Projection")
162
 
163
- with gr.Tab("🤖 AI Forecast Summary"):
164
  with gr.Row():
165
- predicted_high = gr.Textbox(label="Predicted High (30d)", interactive=False)
166
- predicted_low = gr.Textbox(label="Predicted Low (30d)", interactive=False)
167
- predicted_change = gr.Textbox(label="Expected Change (%)", interactive=False)
168
- gr.Markdown("---")
169
  prediction_summary = gr.Markdown()
170
 
171
  analyze_button.click(
 
14
 
15
  warnings.filterwarnings("ignore")
16
 
17
+
18
  def analyze_stock(symbol, prediction_days=30):
19
  try:
20
  if not symbol.strip():
 
33
  signals = generate_trading_signals(data, indicators)
34
  fundamental_info = get_fundamental_data(stock)
35
  predictions = predict_prices(data, prediction_days=prediction_days)
36
+
37
  fig_price = create_price_chart(data, indicators)
38
  fig_technical = create_technical_chart(data, indicators)
39
  fig_prediction = create_prediction_chart(data, predictions)
40
 
41
  return fundamental_info, indicators, signals, fig_price, fig_technical, fig_prediction, predictions
42
+
43
  except Exception as e:
44
  print(f"Error analyzing {symbol}: {e}")
45
  empty_fig = gr.Plot.update(value=None)
46
  empty_predictions = {
47
+ "high_30d": 0,
48
+ "low_30d": 0,
49
+ "change_pct": 0,
50
+ "summary": "Prediction unavailable.",
51
  }
52
  return {}, {}, {}, empty_fig, empty_fig, empty_fig, empty_predictions
53
 
54
+
55
  def update_analysis(symbol, prediction_days):
56
  (
57
  fundamental_info,
 
65
 
66
  if not fundamental_info:
67
  return (
68
+ "Unable to fetch stock data.",
69
+ "No technical signals available.",
70
  gr.Plot.update(value=None),
71
  gr.Plot.update(value=None),
72
  gr.Plot.update(value=None),
73
+ "0",
74
+ "0",
75
+ "0",
76
+ "No prediction data available.",
77
  )
78
 
79
  fundamentals = f"""
80
+ #### COMPANY FUNDAMENTALS
81
+ **Name:** {fundamental_info.get('name', 'N/A')} ({symbol.upper()})
82
  **Current Price:** Rp{fundamental_info.get('current_price', 0):,.2f}
83
  **Market Cap:** {fundamental_info.get('market_cap', 0):,}
84
  **P/E Ratio:** {fundamental_info.get('pe_ratio', 0):.2f}
 
87
  """
88
 
89
  trading_signal = f"""
90
+ #### TECHNICAL SIGNAL SUMMARY
91
  **Overall Trend:** {signals.get('overall', 'N/A')}
92
  **Signal Strength:** {signals.get('strength', 0):.2f}%
93
+ **Support:** Rp{signals.get('support', 0):,.2f}
94
+ **Resistance:** Rp{signals.get('resistance', 0):,.2f}
95
+ **Stop Loss:** Rp{signals.get('stop_loss', 0):,.2f}
96
 
97
+ **Detailed Signals:**
98
  {signals.get('details', '')}
99
  """
100
 
101
  prediction = f"""
102
+ #### 30-DAY AI FORECAST (CHRONOS-BOLT)
103
  **Predicted High:** Rp{predictions.get('high_30d', 0):,.2f}
104
  **Predicted Low:** Rp{predictions.get('low_30d', 0):,.2f}
105
  **Expected Change:** {predictions.get('change_pct', 0):.2f}%
106
 
107
+ **Model Insight:**
108
  {predictions.get('summary', 'No analysis available')}
109
  """
110
 
 
120
  prediction,
121
  )
122
 
123
+
124
  with gr.Blocks(
125
+ title="REXPRO FINANCIAL AI DASHBOARD",
126
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray"),
127
  css="""
128
+ body {
129
+ background-color: #fafafa;
130
+ color: #1e293b;
131
+ font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
132
+ }
133
+ h1 {
134
+ color: #1e40af;
135
+ text-align: center;
136
+ font-weight: 700;
137
+ letter-spacing: 0.5px;
138
+ }
139
+ h2, h3, h4 {
140
+ color: #1e3a8a;
141
+ font-weight: 600;
142
+ }
143
+ .gr-markdown {
144
+ background-color: #ffffff;
145
+ border-radius: 10px;
146
+ border: 1px solid #e2e8f0;
147
+ padding: 16px;
148
+ }
149
+ .gr-button {
150
+ background-color: #2563eb !important;
151
+ color: white !important;
152
+ font-weight: 600;
153
+ border-radius: 8px;
154
+ padding: 10px 18px;
155
+ }
156
+ .gr-textbox input {
157
+ background-color: #ffffff !important;
158
+ color: #1e293b !important;
159
+ }
160
+ .gr-slider {
161
+ background-color: #ffffff !important;
162
+ }
163
+ .gr-plot {
164
+ background-color: #ffffff;
165
+ border: 1px solid #e2e8f0;
166
+ border-radius: 10px;
167
+ }
168
+ """,
169
  ) as app:
170
+ gr.Markdown("# REXPRO FINANCIAL AI DASHBOARD")
171
+ gr.Markdown(
172
+ "A modern financial intelligence dashboard powered by **AI forecasting and technical analytics.**"
173
+ )
174
 
175
+ with gr.Row():
176
  symbol = gr.Textbox(
177
+ label="STOCK SYMBOL (IDX)",
178
  value="BBCA",
179
+ placeholder="Example: BBCA, TLKM, ADRO, BMRI",
180
  interactive=True,
 
181
  )
182
  prediction_days = gr.Slider(
183
+ label="FORECAST PERIOD (DAYS)",
184
  minimum=5,
185
  maximum=60,
186
  step=5,
187
  value=30,
188
  interactive=True,
189
  )
190
+ analyze_button = gr.Button("RUN ANALYSIS")
191
 
192
+ gr.Markdown("___")
193
 
194
  with gr.Row():
195
  with gr.Column(scale=1):
 
197
  with gr.Column(scale=1):
198
  signal_output = gr.Markdown()
199
 
200
+ gr.Markdown("___")
201
 
202
+ with gr.Tab("MARKET CHARTS"):
203
  with gr.Row():
204
+ price_chart = gr.Plot(label="PRICE & MOVING AVERAGES")
205
+ technical_chart = gr.Plot(label="TECHNICAL INDICATORS OVERVIEW")
206
+ gr.Markdown("___")
207
+ prediction_chart = gr.Plot(label="AI FORECAST PROJECTION")
208
 
209
+ with gr.Tab("AI FORECAST SUMMARY"):
210
  with gr.Row():
211
+ predicted_high = gr.Textbox(label="PREDICTED HIGH (30D)", interactive=False)
212
+ predicted_low = gr.Textbox(label="PREDICTED LOW (30D)", interactive=False)
213
+ predicted_change = gr.Textbox(label="EXPECTED CHANGE (%)", interactive=False)
214
+ gr.Markdown("___")
215
  prediction_summary = gr.Markdown()
216
 
217
  analyze_button.click(