omniverse1 commited on
Commit
37a2367
·
verified ·
1 Parent(s): c54bdd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -26
app.py CHANGED
@@ -24,7 +24,6 @@ def analyze_stock(symbol, prediction_days=30):
24
  symbol = symbol.upper() + ".JK"
25
 
26
  stock = yf.Ticker(symbol)
27
- # Fetching data for a slightly longer period for better analysis base
28
  data = stock.history(period="1y", interval="1d")
29
 
30
  if data.empty:
@@ -39,7 +38,6 @@ def analyze_stock(symbol, prediction_days=30):
39
  fig_technical = create_technical_chart(data, indicators)
40
  fig_prediction = create_prediction_chart(data, predictions)
41
 
42
- # kalkulasi TP1, TP2, SL
43
  last_price = data['Close'].iloc[-1]
44
  tp1 = last_price * (1 + (predictions.get("change_pct", 0) / 200))
45
  tp2 = last_price * (1 + (predictions.get("change_pct", 0) / 100))
@@ -63,7 +61,6 @@ def analyze_stock(symbol, prediction_days=30):
63
  "tp2": 0,
64
  "sl": 0,
65
  }
66
- # Mengembalikan string kosong untuk data yang akan ditampilkan di Markdown
67
  return {}, {}, {}, empty_fig, empty_fig, empty_fig, empty_predictions
68
 
69
 
@@ -79,7 +76,6 @@ def update_analysis(symbol, prediction_days):
79
  ) = analyze_stock(symbol, prediction_days)
80
 
81
  if not fundamental_info and "Error" in predictions.get("summary", ""):
82
- # Jika terjadi error, kembalikan hasil error ke semua output
83
  error_msg = f"**ERROR:** {predictions.get('summary')}"
84
  return (
85
  gr.Markdown.update(value=error_msg),
@@ -90,7 +86,6 @@ def update_analysis(symbol, prediction_days):
90
  gr.Plot.update(value=None),
91
  )
92
 
93
- # --- Formatting Fundamental Data ---
94
  fundamentals_text = f"""
95
  ### COMPANY FUNDAMENTALS
96
  - **Name:** {fundamental_info.get('name', 'N/A')} ({symbol.upper()})
@@ -101,7 +96,6 @@ def update_analysis(symbol, prediction_days):
101
  - **Volume:** {fundamental_info.get('volume', 0):,}
102
  """
103
 
104
- # --- Formatting Technical Signals ---
105
  details_list = "".join(
106
  [f"<li>{line.strip()}</li>" for line in signals.get("details", "").split("\n") if line.strip()]
107
  )
@@ -120,7 +114,6 @@ def update_analysis(symbol, prediction_days):
120
  </ul>
121
  """
122
 
123
- # --- Formatting Prediction Data ---
124
  prediction_text = f"""
125
  ### 30-DAY AI FORECAST
126
  - **Predicted High:** Rp{predictions.get('high_30d', 0):,.2f}
@@ -146,18 +139,15 @@ def update_analysis(symbol, prediction_days):
146
  )
147
 
148
 
149
- # --- STRUKTUR UI BARU ---
150
  with gr.Blocks(
151
  title="REXPRO FINANCIAL AI DASHBOARD",
152
- # Menggunakan tema standar Gradio. Perbaikan layout yang membuat professional.
153
  ) as app:
154
  gr.Markdown("# REXPRO FINANCIAL AI DASHBOARD")
155
  gr.Markdown(
156
  "Aplikasi Analisis Saham Komprehensif IDX, didukung oleh **Peramalan AI (CHRONOS-BOLT)** dan Analisis Teknikal."
157
  )
158
 
159
- # 1. Row Kontrol Utama
160
- with gr.Row(variant="panel"): # Menggunakan panel untuk membedakan area kontrol
161
  with gr.Column(scale=1):
162
  symbol = gr.Textbox(
163
  label="MASUKKAN SIMBOL SAHAM (IDX)",
@@ -177,55 +167,43 @@ with gr.Blocks(
177
  show_label=True
178
  )
179
  with gr.Column(min_width=150, scale=0):
180
- # Tombol diletakkan di bawah input untuk tampilan yang lebih rapi
181
  analyze_button = gr.Button("RUN ANALYSIS", size="lg")
182
 
183
- # 2. Tab untuk Hasil
184
  with gr.Tabs():
185
- # Tab 1: Ringkasan Analisis (Textual)
186
  with gr.TabItem("RINGKASAN & TARGET"):
187
- # Menggunakan gr.Row untuk membuat 3 "kartu" atau kolom hasil
188
  with gr.Row():
189
- # Grup untuk Fundamental
190
  with gr.Group():
191
  fundamentals_output = gr.Markdown(
192
  "Hasil Fundamental akan muncul di sini.",
193
  elem_classes=["card"]
194
  )
195
- # Grup untuk Sinyal Teknikal
196
  with gr.Group():
197
  trading_signal_output = gr.Markdown(
198
  "Ringkasan Sinyal Teknikal akan muncul di sini.",
199
  elem_classes=["card"]
200
  )
201
- # Grup untuk Prediksi AI & Target
202
  with gr.Group():
203
  prediction_output = gr.Markdown(
204
  "Hasil Peramalan AI & Target Trading akan muncul di sini.",
205
  elem_classes=["card"]
206
  )
207
 
208
- # Tab 2: Grafik Analisis
209
  with gr.TabItem("VISUALISASI GRAFIK"):
210
  gr.Markdown("## Grafik Analisis Saham")
211
 
212
  with gr.Row():
213
- # Grafik 1: Harga & MA
214
  with gr.Column(scale=1):
215
- price_chart = gr.Plot(label="1. HARGA & RATA-RATA BERGERAK (MA)", height=450)
216
 
217
- # Grafik 2: Indikator Teknikal
218
  with gr.Column(scale=1):
219
- technical_chart = gr.Plot(label="2. INDIKATOR TEKNIKAL UTAMA (RSI/MACD)", height=450)
220
 
221
  gr.Markdown("---")
222
 
223
  with gr.Row():
224
- # Grafik 3: Prediksi AI
225
- prediction_chart = gr.Plot(label="3. PROYEKSI PERAMALAN AI", height=500)
226
 
227
 
228
- # Definisi Event Handler
229
  analyze_button.click(
230
  fn=update_analysis,
231
  inputs=[symbol, prediction_days],
 
24
  symbol = symbol.upper() + ".JK"
25
 
26
  stock = yf.Ticker(symbol)
 
27
  data = stock.history(period="1y", interval="1d")
28
 
29
  if data.empty:
 
38
  fig_technical = create_technical_chart(data, indicators)
39
  fig_prediction = create_prediction_chart(data, predictions)
40
 
 
41
  last_price = data['Close'].iloc[-1]
42
  tp1 = last_price * (1 + (predictions.get("change_pct", 0) / 200))
43
  tp2 = last_price * (1 + (predictions.get("change_pct", 0) / 100))
 
61
  "tp2": 0,
62
  "sl": 0,
63
  }
 
64
  return {}, {}, {}, empty_fig, empty_fig, empty_fig, empty_predictions
65
 
66
 
 
76
  ) = analyze_stock(symbol, prediction_days)
77
 
78
  if not fundamental_info and "Error" in predictions.get("summary", ""):
 
79
  error_msg = f"**ERROR:** {predictions.get('summary')}"
80
  return (
81
  gr.Markdown.update(value=error_msg),
 
86
  gr.Plot.update(value=None),
87
  )
88
 
 
89
  fundamentals_text = f"""
90
  ### COMPANY FUNDAMENTALS
91
  - **Name:** {fundamental_info.get('name', 'N/A')} ({symbol.upper()})
 
96
  - **Volume:** {fundamental_info.get('volume', 0):,}
97
  """
98
 
 
99
  details_list = "".join(
100
  [f"<li>{line.strip()}</li>" for line in signals.get("details", "").split("\n") if line.strip()]
101
  )
 
114
  </ul>
115
  """
116
 
 
117
  prediction_text = f"""
118
  ### 30-DAY AI FORECAST
119
  - **Predicted High:** Rp{predictions.get('high_30d', 0):,.2f}
 
139
  )
140
 
141
 
 
142
  with gr.Blocks(
143
  title="REXPRO FINANCIAL AI DASHBOARD",
 
144
  ) as app:
145
  gr.Markdown("# REXPRO FINANCIAL AI DASHBOARD")
146
  gr.Markdown(
147
  "Aplikasi Analisis Saham Komprehensif IDX, didukung oleh **Peramalan AI (CHRONOS-BOLT)** dan Analisis Teknikal."
148
  )
149
 
150
+ with gr.Row(variant="panel"):
 
151
  with gr.Column(scale=1):
152
  symbol = gr.Textbox(
153
  label="MASUKKAN SIMBOL SAHAM (IDX)",
 
167
  show_label=True
168
  )
169
  with gr.Column(min_width=150, scale=0):
 
170
  analyze_button = gr.Button("RUN ANALYSIS", size="lg")
171
 
 
172
  with gr.Tabs():
 
173
  with gr.TabItem("RINGKASAN & TARGET"):
 
174
  with gr.Row():
 
175
  with gr.Group():
176
  fundamentals_output = gr.Markdown(
177
  "Hasil Fundamental akan muncul di sini.",
178
  elem_classes=["card"]
179
  )
 
180
  with gr.Group():
181
  trading_signal_output = gr.Markdown(
182
  "Ringkasan Sinyal Teknikal akan muncul di sini.",
183
  elem_classes=["card"]
184
  )
 
185
  with gr.Group():
186
  prediction_output = gr.Markdown(
187
  "Hasil Peramalan AI & Target Trading akan muncul di sini.",
188
  elem_classes=["card"]
189
  )
190
 
 
191
  with gr.TabItem("VISUALISASI GRAFIK"):
192
  gr.Markdown("## Grafik Analisis Saham")
193
 
194
  with gr.Row():
 
195
  with gr.Column(scale=1):
196
+ price_chart = gr.Plot(label="1. HARGA & RATA-RATA BERGERAK (MA)")
197
 
 
198
  with gr.Column(scale=1):
199
+ technical_chart = gr.Plot(label="2. INDIKATOR TEKNIKAL UTAMA (RSI/MACD)")
200
 
201
  gr.Markdown("---")
202
 
203
  with gr.Row():
204
+ prediction_chart = gr.Plot(label="3. PROYEKSI PERAMALAN AI")
 
205
 
206
 
 
207
  analyze_button.click(
208
  fn=update_analysis,
209
  inputs=[symbol, prediction_days],