Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ def create_chart_analysis(ticker, interval):
|
|
| 20 |
# Panggil fungsi data yang sudah diperbarui
|
| 21 |
df = data_processor.get_market_data(ticker, interval)
|
| 22 |
if df.empty:
|
| 23 |
-
return "No data available", None
|
| 24 |
|
| 25 |
# Hitung indikator
|
| 26 |
df = data_processor.calculate_indicators(df)
|
|
@@ -63,7 +63,7 @@ def create_chart_analysis(ticker, interval):
|
|
| 63 |
"Volume": f"{df['Volume'].iloc[-1]:,.0f}"
|
| 64 |
}
|
| 65 |
|
| 66 |
-
#
|
| 67 |
return chart_html, metrics
|
| 68 |
|
| 69 |
except Exception as e:
|
|
@@ -71,14 +71,13 @@ def create_chart_analysis(ticker, interval):
|
|
| 71 |
|
| 72 |
def analyze_sentiment(ticker):
|
| 73 |
"""Analyze gold/crypto market sentiment"""
|
| 74 |
-
sentiment_score = np.random.uniform(-0.5, 0.5)
|
| 75 |
|
| 76 |
# Mock news summary
|
| 77 |
news_html = "<div style='max-height: 200px; overflow-y: auto; color: black;'>"
|
| 78 |
news_html += f"<h4 style='color: #FFD700;'>Latest {ticker} News (Mock)</h4>"
|
| 79 |
news_html += "</div>"
|
| 80 |
|
| 81 |
-
# ... (Logika Gauge Chart, tetap sama)
|
| 82 |
fig = go.Figure(go.Indicator(
|
| 83 |
mode="gauge+number+delta",
|
| 84 |
value=sentiment_score,
|
|
@@ -102,10 +101,8 @@ def analyze_sentiment(ticker):
|
|
| 102 |
))
|
| 103 |
|
| 104 |
fig.update_layout(
|
| 105 |
-
# Tema Putih
|
| 106 |
template='plotly_white',
|
| 107 |
height=300,
|
| 108 |
-
# Warna background figure diubah menjadi terang
|
| 109 |
paper_bgcolor='#f0f4f9',
|
| 110 |
plot_bgcolor='#f0f4f9',
|
| 111 |
font=dict(color='black')
|
|
@@ -116,7 +113,6 @@ def analyze_sentiment(ticker):
|
|
| 116 |
def get_fundamentals(ticker):
|
| 117 |
"""Get fundamental analysis data"""
|
| 118 |
try:
|
| 119 |
-
# Panggil fungsi fundamental data yang sudah diperbarui (tetap mock)
|
| 120 |
fundamentals = data_processor.get_fundamental_data(ticker)
|
| 121 |
|
| 122 |
# Buat fundamentals table
|
|
@@ -153,10 +149,8 @@ def get_fundamentals(ticker):
|
|
| 153 |
))
|
| 154 |
|
| 155 |
fig.update_layout(
|
| 156 |
-
# Tema Putih
|
| 157 |
template='plotly_white',
|
| 158 |
height=300,
|
| 159 |
-
# Warna background figure diubah menjadi terang
|
| 160 |
paper_bgcolor='#f0f4f9',
|
| 161 |
plot_bgcolor='#f0f4f9',
|
| 162 |
font=dict(color='black')
|
|
@@ -171,7 +165,6 @@ def get_fundamentals(ticker):
|
|
| 171 |
with gr.Blocks(
|
| 172 |
theme=gr.themes.Default(primary_hue="yellow", secondary_hue="yellow"),
|
| 173 |
title="Ultimate Market Analysis & Prediction",
|
| 174 |
-
# CSS diubah ke tema terang (#f0f4f9 sebagai background)
|
| 175 |
css="""
|
| 176 |
.gradio-container {background-color: #f0f4f9; color: black}
|
| 177 |
.gr-button-primary {background-color: #FFD700 !important; color: #000000 !important}
|
|
@@ -180,7 +173,6 @@ with gr.Blocks(
|
|
| 180 |
.gr-tab button.selected {background-color: #FFD700 !important; color: #000000 !important}
|
| 181 |
.gr-highlighted {background-color: #CCCCCC !important}
|
| 182 |
.anycoder-link {color: #FFD700 !important; text-decoration: none; font-weight: bold}
|
| 183 |
-
/* Custom CSS untuk chart MPLFinance agar tampil penuh */
|
| 184 |
.mpl-chart-container {
|
| 185 |
border: 1px solid #CCCCCC;
|
| 186 |
border-radius: 5px;
|
|
@@ -188,7 +180,6 @@ with gr.Blocks(
|
|
| 188 |
background: white;
|
| 189 |
width: 100%;
|
| 190 |
}
|
| 191 |
-
/* Mengatasi teks Plotly di tema terang */
|
| 192 |
.chart-title {color: black !important;}
|
| 193 |
.metric-label {color: black !important;}
|
| 194 |
"""
|
|
@@ -225,7 +216,6 @@ with gr.Blocks(
|
|
| 225 |
chart_html = gr.HTML(label="Price Chart & Indicators", elem_classes=["mpl-chart-container"])
|
| 226 |
|
| 227 |
with gr.Row():
|
| 228 |
-
# Menghapus pred_plot yang kosong
|
| 229 |
metrics_output = gr.JSON(label="Trading Metrics")
|
| 230 |
|
| 231 |
with gr.TabItem("堂 Sentiment Analysis"):
|
|
@@ -244,22 +234,22 @@ with gr.Blocks(
|
|
| 244 |
|
| 245 |
# Event handlers
|
| 246 |
def update_all(ticker, interval):
|
| 247 |
-
#
|
| 248 |
chart, metrics = create_chart_analysis(ticker, interval)
|
| 249 |
sentiment_gauge, news_display = analyze_sentiment(ticker)
|
| 250 |
fund_gauge, fund_table = get_fundamentals(ticker)
|
| 251 |
|
| 252 |
-
#
|
| 253 |
-
|
| 254 |
-
return chart, metrics, None, sentiment_gauge, news_display, fund_gauge, fund_table
|
| 255 |
|
| 256 |
-
# OUTPUTS: chart_html, metrics_output,
|
| 257 |
|
|
|
|
| 258 |
refresh_btn.click(
|
| 259 |
fn=update_all,
|
| 260 |
inputs=[ticker_dropdown, interval_dropdown],
|
| 261 |
outputs=[
|
| 262 |
-
chart_html, metrics_output,
|
| 263 |
sentiment_gauge, news_display,
|
| 264 |
fundamentals_gauge, fundamentals_table
|
| 265 |
]
|
|
@@ -269,7 +259,7 @@ with gr.Blocks(
|
|
| 269 |
fn=update_all,
|
| 270 |
inputs=[ticker_dropdown, interval_dropdown],
|
| 271 |
outputs=[
|
| 272 |
-
chart_html, metrics_output,
|
| 273 |
sentiment_gauge, news_display,
|
| 274 |
fundamentals_gauge, fundamentals_table
|
| 275 |
]
|
|
|
|
| 20 |
# Panggil fungsi data yang sudah diperbarui
|
| 21 |
df = data_processor.get_market_data(ticker, interval)
|
| 22 |
if df.empty:
|
| 23 |
+
return "No data available", None
|
| 24 |
|
| 25 |
# Hitung indikator
|
| 26 |
df = data_processor.calculate_indicators(df)
|
|
|
|
| 63 |
"Volume": f"{df['Volume'].iloc[-1]:,.0f}"
|
| 64 |
}
|
| 65 |
|
| 66 |
+
# FIX: Hanya mengembalikan 2 output untuk Chart Analysis
|
| 67 |
return chart_html, metrics
|
| 68 |
|
| 69 |
except Exception as e:
|
|
|
|
| 71 |
|
| 72 |
def analyze_sentiment(ticker):
|
| 73 |
"""Analyze gold/crypto market sentiment"""
|
| 74 |
+
sentiment_score = np.random.uniform(-0.5, 0.5)
|
| 75 |
|
| 76 |
# Mock news summary
|
| 77 |
news_html = "<div style='max-height: 200px; overflow-y: auto; color: black;'>"
|
| 78 |
news_html += f"<h4 style='color: #FFD700;'>Latest {ticker} News (Mock)</h4>"
|
| 79 |
news_html += "</div>"
|
| 80 |
|
|
|
|
| 81 |
fig = go.Figure(go.Indicator(
|
| 82 |
mode="gauge+number+delta",
|
| 83 |
value=sentiment_score,
|
|
|
|
| 101 |
))
|
| 102 |
|
| 103 |
fig.update_layout(
|
|
|
|
| 104 |
template='plotly_white',
|
| 105 |
height=300,
|
|
|
|
| 106 |
paper_bgcolor='#f0f4f9',
|
| 107 |
plot_bgcolor='#f0f4f9',
|
| 108 |
font=dict(color='black')
|
|
|
|
| 113 |
def get_fundamentals(ticker):
|
| 114 |
"""Get fundamental analysis data"""
|
| 115 |
try:
|
|
|
|
| 116 |
fundamentals = data_processor.get_fundamental_data(ticker)
|
| 117 |
|
| 118 |
# Buat fundamentals table
|
|
|
|
| 149 |
))
|
| 150 |
|
| 151 |
fig.update_layout(
|
|
|
|
| 152 |
template='plotly_white',
|
| 153 |
height=300,
|
|
|
|
| 154 |
paper_bgcolor='#f0f4f9',
|
| 155 |
plot_bgcolor='#f0f4f9',
|
| 156 |
font=dict(color='black')
|
|
|
|
| 165 |
with gr.Blocks(
|
| 166 |
theme=gr.themes.Default(primary_hue="yellow", secondary_hue="yellow"),
|
| 167 |
title="Ultimate Market Analysis & Prediction",
|
|
|
|
| 168 |
css="""
|
| 169 |
.gradio-container {background-color: #f0f4f9; color: black}
|
| 170 |
.gr-button-primary {background-color: #FFD700 !important; color: #000000 !important}
|
|
|
|
| 173 |
.gr-tab button.selected {background-color: #FFD700 !important; color: #000000 !important}
|
| 174 |
.gr-highlighted {background-color: #CCCCCC !important}
|
| 175 |
.anycoder-link {color: #FFD700 !important; text-decoration: none; font-weight: bold}
|
|
|
|
| 176 |
.mpl-chart-container {
|
| 177 |
border: 1px solid #CCCCCC;
|
| 178 |
border-radius: 5px;
|
|
|
|
| 180 |
background: white;
|
| 181 |
width: 100%;
|
| 182 |
}
|
|
|
|
| 183 |
.chart-title {color: black !important;}
|
| 184 |
.metric-label {color: black !important;}
|
| 185 |
"""
|
|
|
|
| 216 |
chart_html = gr.HTML(label="Price Chart & Indicators", elem_classes=["mpl-chart-container"])
|
| 217 |
|
| 218 |
with gr.Row():
|
|
|
|
| 219 |
metrics_output = gr.JSON(label="Trading Metrics")
|
| 220 |
|
| 221 |
with gr.TabItem("堂 Sentiment Analysis"):
|
|
|
|
| 234 |
|
| 235 |
# Event handlers
|
| 236 |
def update_all(ticker, interval):
|
| 237 |
+
# FIX: create_chart_analysis sekarang hanya mengembalikan 2 output
|
| 238 |
chart, metrics = create_chart_analysis(ticker, interval)
|
| 239 |
sentiment_gauge, news_display = analyze_sentiment(ticker)
|
| 240 |
fund_gauge, fund_table = get_fundamentals(ticker)
|
| 241 |
|
| 242 |
+
# Total 5 outputs Gradio components
|
| 243 |
+
return chart, metrics, sentiment_gauge, news_display, fund_gauge, fund_table
|
|
|
|
| 244 |
|
| 245 |
+
# OUTPUTS: chart_html, metrics_output, sentiment_gauge, news_display, fundamentals_gauge, fundamentals_table
|
| 246 |
|
| 247 |
+
# FIX: Menghapus output pred_plot (diganti dengan None) dan menyesuaikan list outputs
|
| 248 |
refresh_btn.click(
|
| 249 |
fn=update_all,
|
| 250 |
inputs=[ticker_dropdown, interval_dropdown],
|
| 251 |
outputs=[
|
| 252 |
+
chart_html, metrics_output,
|
| 253 |
sentiment_gauge, news_display,
|
| 254 |
fundamentals_gauge, fundamentals_table
|
| 255 |
]
|
|
|
|
| 259 |
fn=update_all,
|
| 260 |
inputs=[ticker_dropdown, interval_dropdown],
|
| 261 |
outputs=[
|
| 262 |
+
chart_html, metrics_output,
|
| 263 |
sentiment_gauge, news_display,
|
| 264 |
fundamentals_gauge, fundamentals_table
|
| 265 |
]
|