omniverse1 commited on
Commit
dbe373a
·
verified ·
1 Parent(s): c67acf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -81
app.py CHANGED
@@ -38,6 +38,16 @@ def analyze_stock(symbol, prediction_days=30):
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:
@@ -67,60 +77,61 @@ def update_analysis(symbol, prediction_days):
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
- <h4>COMPANY FUNDAMENTALS</h4>
81
- <b>Name:</b> {fundamental_info.get('name', 'N/A')} ({symbol.upper()})<br>
82
- <b>Current Price:</b> Rp{fundamental_info.get('current_price', 0):,.2f}<br>
83
- <b>Market Cap:</b> {fundamental_info.get('market_cap', 0):,}<br>
84
- <b>P/E Ratio:</b> {fundamental_info.get('pe_ratio', 0):.2f}<br>
85
- <b>Dividend Yield:</b> {fundamental_info.get('dividend_yield', 0):.2f}%<br>
86
- <b>Volume:</b> {fundamental_info.get('volume', 0):,}<br>
87
- """
88
 
89
  details_list = "".join(
90
  [f"<li>{line.strip()}</li>" for line in signals.get("details", "").split("\n") if line.strip()]
91
  )
92
 
93
  trading_signal = f"""
94
- <h4>TECHNICAL SIGNAL SUMMARY</h4>
95
- <b>Overall Trend:</b> {signals.get('overall', 'N/A')}<br>
96
- <b>Signal Strength:</b> {signals.get('strength', 0):.2f}%<br>
97
- <b>Support:</b> Rp{signals.get('support', 0):,.2f}<br>
98
- <b>Resistance:</b> Rp{signals.get('resistance', 0):,.2f}<br>
99
- <b>Stop Loss:</b> Rp{signals.get('stop_loss', 0):,.2f}<br><br>
100
- <b>Detailed Signals:</b>
101
- <ul style="margin-top: 8px; padding-left: 20px; line-height: 1.6;">
102
- {details_list}
103
- </ul>
104
- """
105
 
106
  prediction = f"""
107
- <h4>30-DAY AI FORECAST (CHRONOS-BOLT)</h4>
108
- <b>Predicted High:</b> Rp{predictions.get('high_30d', 0):,.2f}<br>
109
- <b>Predicted Low:</b> Rp{predictions.get('low_30d', 0):,.2f}<br>
110
- <b>Expected Change:</b> {predictions.get('change_pct', 0):.2f}%<br><br>
111
- <b>Model Insight:</b><br>{predictions.get('summary', 'No analysis available')}
112
- """
 
 
 
113
 
114
  return (
115
- fundamentals,
116
- trading_signal,
 
 
 
 
 
117
  fig_price,
118
  fig_technical,
119
  fig_prediction,
120
- f"{predictions.get('high_30d', 0):,.2f}",
121
- f"{predictions.get('low_30d', 0):,.2f}",
122
- f"{predictions.get('change_pct', 0):.2f}%",
123
- prediction,
124
  )
125
 
126
 
@@ -145,12 +156,6 @@ with gr.Blocks(
145
  font-weight: 600;
146
  margin-bottom: 6px;
147
  }
148
- .gr-markdown {
149
- background-color: #ffffff;
150
- border-radius: 10px;
151
- border: 1px solid #e2e8f0;
152
- padding: 16px;
153
- }
154
  .gr-button {
155
  background-color: #2563eb !important;
156
  color: white !important;
@@ -158,31 +163,33 @@ with gr.Blocks(
158
  border-radius: 8px;
159
  padding: 10px 18px;
160
  }
161
- .gr-textbox input {
162
- background-color: #ffffff !important;
163
- color: #1e293b !important;
164
- border: 1px solid #d1d5db !important;
 
 
 
165
  }
166
- .gr-slider {
167
- background-color: #ffffff !important;
 
 
 
 
168
  }
 
 
169
  .gr-plot {
170
  background-color: #ffffff;
171
  border: 1px solid #e2e8f0;
172
  border-radius: 10px;
173
  }
174
- ul {
175
- margin: 0;
176
- padding: 0 0 0 18px;
177
- }
178
- li {
179
- margin-bottom: 4px;
180
- }
181
  """,
182
  ) as app:
183
  gr.Markdown("# REXPRO FINANCIAL AI DASHBOARD")
184
  gr.Markdown(
185
- "A modern financial intelligence dashboard powered by **AI forecasting and technical analytics.**"
186
  )
187
 
188
  with gr.Row():
@@ -203,13 +210,7 @@ with gr.Blocks(
203
  analyze_button = gr.Button("RUN ANALYSIS")
204
 
205
  gr.Markdown("---")
206
-
207
- with gr.Row():
208
- with gr.Column(scale=1):
209
- fundamentals_output = gr.HTML()
210
- with gr.Column(scale=1):
211
- signal_output = gr.HTML()
212
-
213
  gr.Markdown("---")
214
 
215
  with gr.Tab("MARKET CHARTS"):
@@ -219,28 +220,10 @@ with gr.Blocks(
219
  gr.Markdown("---")
220
  prediction_chart = gr.Plot(label="AI FORECAST PROJECTION")
221
 
222
- with gr.Tab("AI FORECAST SUMMARY"):
223
- with gr.Row():
224
- predicted_high = gr.Textbox(label="PREDICTED HIGH (30D)", interactive=False)
225
- predicted_low = gr.Textbox(label="PREDICTED LOW (30D)", interactive=False)
226
- predicted_change = gr.Textbox(label="EXPECTED CHANGE (%)", interactive=False)
227
- gr.Markdown("---")
228
- prediction_summary = gr.HTML()
229
-
230
  analyze_button.click(
231
  fn=update_analysis,
232
  inputs=[symbol, prediction_days],
233
- outputs=[
234
- fundamentals_output,
235
- signal_output,
236
- price_chart,
237
- technical_chart,
238
- prediction_chart,
239
- predicted_high,
240
- predicted_low,
241
- predicted_change,
242
- prediction_summary,
243
- ],
244
  )
245
 
246
  if __name__ == "__main__":
 
38
  fig_technical = create_technical_chart(data, indicators)
39
  fig_prediction = create_prediction_chart(data, predictions)
40
 
41
+ # kalkulasi TP1, TP2, SL
42
+ last_price = data['Close'].iloc[-1]
43
+ tp1 = last_price * (1 + (predictions.get("change_pct", 0) / 200))
44
+ tp2 = last_price * (1 + (predictions.get("change_pct", 0) / 100))
45
+ sl = last_price * 0.95
46
+
47
+ predictions["tp1"] = tp1
48
+ predictions["tp2"] = tp2
49
+ predictions["sl"] = sl
50
+
51
  return fundamental_info, indicators, signals, fig_price, fig_technical, fig_prediction, predictions
52
 
53
  except Exception as e:
 
77
  return (
78
  "Unable to fetch stock data.",
79
  "No technical signals available.",
80
+ "No prediction data available.",
81
  gr.Plot.update(value=None),
82
  gr.Plot.update(value=None),
83
  gr.Plot.update(value=None),
 
 
 
 
84
  )
85
 
86
  fundamentals = f"""
87
+ <h4>COMPANY FUNDAMENTALS</h4>
88
+ <b>Name:</b> {fundamental_info.get('name', 'N/A')} ({symbol.upper()})<br>
89
+ <b>Current Price:</b> Rp{fundamental_info.get('current_price', 0):,.2f}<br>
90
+ <b>Market Cap:</b> {fundamental_info.get('market_cap', 0):,}<br>
91
+ <b>P/E Ratio:</b> {fundamental_info.get('pe_ratio', 0):.2f}<br>
92
+ <b>Dividend Yield:</b> {fundamental_info.get('dividend_yield', 0):.2f}%<br>
93
+ <b>Volume:</b> {fundamental_info.get('volume', 0):,}<br>
94
+ """
95
 
96
  details_list = "".join(
97
  [f"<li>{line.strip()}</li>" for line in signals.get("details", "").split("\n") if line.strip()]
98
  )
99
 
100
  trading_signal = f"""
101
+ <h4>TECHNICAL SIGNAL SUMMARY</h4>
102
+ <b>Overall Trend:</b> {signals.get('overall', 'N/A')}<br>
103
+ <b>Signal Strength:</b> {signals.get('strength', 0):.2f}%<br>
104
+ <b>Support:</b> Rp{signals.get('support', 0):,.2f}<br>
105
+ <b>Resistance:</b> Rp{signals.get('resistance', 0):,.2f}<br>
106
+ <b>Stop Loss:</b> Rp{signals.get('stop_loss', 0):,.2f}<br><br>
107
+ <b>Detailed Signals:</b>
108
+ <ul style="margin-top: 8px; padding-left: 20px; line-height: 1.6;">
109
+ {details_list}
110
+ </ul>
111
+ """
112
 
113
  prediction = f"""
114
+ <h4>30-DAY AI FORECAST (CHRONOS-BOLT)</h4>
115
+ <b>Predicted High:</b> Rp{predictions.get('high_30d', 0):,.2f}<br>
116
+ <b>Predicted Low:</b> Rp{predictions.get('low_30d', 0):,.2f}<br>
117
+ <b>Expected Change:</b> {predictions.get('change_pct', 0):.2f}%<br><br>
118
+ <b>TP1:</b> Rp{predictions.get('tp1', 0):,.2f}<br>
119
+ <b>TP2:</b> Rp{predictions.get('tp2', 0):,.2f}<br>
120
+ <b>Stop Loss:</b> Rp{predictions.get('sl', 0):,.2f}<br><br>
121
+ <b>Model Insight:</b><br>{predictions.get('summary', 'No analysis available')}
122
+ """
123
 
124
  return (
125
+ f"""
126
+ <div class='triple-panel'>
127
+ <div class='panel-box'>{fundamentals}</div>
128
+ <div class='panel-box'>{trading_signal}</div>
129
+ <div class='panel-box'>{prediction}</div>
130
+ </div>
131
+ """,
132
  fig_price,
133
  fig_technical,
134
  fig_prediction,
 
 
 
 
135
  )
136
 
137
 
 
156
  font-weight: 600;
157
  margin-bottom: 6px;
158
  }
 
 
 
 
 
 
159
  .gr-button {
160
  background-color: #2563eb !important;
161
  color: white !important;
 
163
  border-radius: 8px;
164
  padding: 10px 18px;
165
  }
166
+ .panel-box {
167
+ background-color: #ffffff;
168
+ border-radius: 10px;
169
+ border: 1px solid #e2e8f0;
170
+ padding: 16px;
171
+ flex: 1;
172
+ min-width: 30%;
173
  }
174
+ .triple-panel {
175
+ display: flex;
176
+ flex-direction: row;
177
+ justify-content: space-between;
178
+ gap: 16px;
179
+ width: 100%;
180
  }
181
+ ul { margin: 0; padding: 0 0 0 18px; }
182
+ li { margin-bottom: 4px; }
183
  .gr-plot {
184
  background-color: #ffffff;
185
  border: 1px solid #e2e8f0;
186
  border-radius: 10px;
187
  }
 
 
 
 
 
 
 
188
  """,
189
  ) as app:
190
  gr.Markdown("# REXPRO FINANCIAL AI DASHBOARD")
191
  gr.Markdown(
192
+ "Comprehensive stock analytics powered by **AI forecasting and technical analysis.**"
193
  )
194
 
195
  with gr.Row():
 
210
  analyze_button = gr.Button("RUN ANALYSIS")
211
 
212
  gr.Markdown("---")
213
+ report_section = gr.HTML()
 
 
 
 
 
 
214
  gr.Markdown("---")
215
 
216
  with gr.Tab("MARKET CHARTS"):
 
220
  gr.Markdown("---")
221
  prediction_chart = gr.Plot(label="AI FORECAST PROJECTION")
222
 
 
 
 
 
 
 
 
 
223
  analyze_button.click(
224
  fn=update_analysis,
225
  inputs=[symbol, prediction_days],
226
+ outputs=[report_section, price_chart, technical_chart, prediction_chart],
 
 
 
 
 
 
 
 
 
 
227
  )
228
 
229
  if __name__ == "__main__":