Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from model_handler import ModelHandler
|
|
| 9 |
from trading_logic import TradingLogic
|
| 10 |
import io
|
| 11 |
import base64
|
|
|
|
| 12 |
|
| 13 |
# Global instances
|
| 14 |
data_processor = DataProcessor()
|
|
@@ -164,62 +165,45 @@ def analyze_sentiment(asset_name):
|
|
| 164 |
"""Analyze market sentiment for selected asset"""
|
| 165 |
try:
|
| 166 |
ticker = asset_map[asset_name]
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
fig
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
# Draw score number (similar to the image)
|
| 202 |
-
score_color = 'red' if sentiment_score < 0 else 'green' if sentiment_score > 0 else 'black'
|
| 203 |
-
ax.text(0, -0.15, f"{sentiment_score:+.3f}", ha='center', va='center',
|
| 204 |
-
fontsize=24, color=score_color, weight='bold', zorder=5)
|
| 205 |
-
|
| 206 |
-
# Add labels for the scale
|
| 207 |
-
ax.text(-1, 0, "-1", ha='center', va='top', fontsize=10, color='black')
|
| 208 |
-
ax.text(-0.5, 0.5, "-0.5", ha='center', va='center', fontsize=10, color='black')
|
| 209 |
-
ax.text(0, 1.05, "0", ha='center', va='bottom', fontsize=10, color='black')
|
| 210 |
-
ax.text(0.5, 0.5, "0.5", ha='center', va='center', fontsize=10, color='black')
|
| 211 |
-
ax.text(1, 0, "1", ha='center', va='top', fontsize=10, color='black')
|
| 212 |
-
|
| 213 |
-
# Add Title
|
| 214 |
-
ax.set_title(f'{ticker} Market Sentiment (Simulated)', color='black', pad=20)
|
| 215 |
-
|
| 216 |
-
# Remove axes
|
| 217 |
-
ax.axis('off')
|
| 218 |
|
| 219 |
return fig, news_summary
|
| 220 |
|
| 221 |
except Exception as e:
|
| 222 |
-
# Return error plot
|
| 223 |
fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
|
| 224 |
fig.patch.set_facecolor('white')
|
| 225 |
ax.text(0.5, 0.5, f'Sentiment Error: {str(e)}', ha='center', va='center',
|
|
@@ -328,10 +312,8 @@ with gr.Blocks(
|
|
| 328 |
|
| 329 |
with gr.TabItem("Sentiment Analysis"):
|
| 330 |
with gr.Row():
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
with gr.Column(scale=1):
|
| 334 |
-
news_display = gr.HTML(label="Market News")
|
| 335 |
|
| 336 |
with gr.TabItem("Fundamentals"):
|
| 337 |
with gr.Row():
|
|
|
|
| 9 |
from trading_logic import TradingLogic
|
| 10 |
import io
|
| 11 |
import base64
|
| 12 |
+
import plotly.graph_objects as go
|
| 13 |
|
| 14 |
# Global instances
|
| 15 |
data_processor = DataProcessor()
|
|
|
|
| 165 |
"""Analyze market sentiment for selected asset"""
|
| 166 |
try:
|
| 167 |
ticker = asset_map[asset_name]
|
| 168 |
+
# FIX: Menggunakan fungsi yang benar dari sentiment_analyzer.py
|
| 169 |
+
sentiment_score, news_summary = sentiment_analyzer.analyze_market_sentiment(ticker)
|
| 170 |
+
|
| 171 |
+
# --- Implementasi Plotly Gauge (sesuai referensi pengguna) ---
|
| 172 |
+
|
| 173 |
+
fig = go.Figure(go.Indicator(
|
| 174 |
+
mode="gauge+number+delta",
|
| 175 |
+
value=sentiment_score,
|
| 176 |
+
domain={'x': [0, 1], 'y': [0, 1]},
|
| 177 |
+
title={'text': f"{ticker} Market Sentiment (Simulated)"},
|
| 178 |
+
delta={'reference': 0},
|
| 179 |
+
gauge={
|
| 180 |
+
'axis': {'range': [-1, 1]},
|
| 181 |
+
'bar': {'color': "#FFD700"},
|
| 182 |
+
'steps': [
|
| 183 |
+
{'range': [-1, -0.5], 'color': "rgba(255,0,0,0.5)"}, # Merah (Bearish)
|
| 184 |
+
{'range': [-0.5, 0.5], 'color': "rgba(100,100,100,0.3)"}, # Abu-abu (Neutral)
|
| 185 |
+
{'range': [0.5, 1], 'color': "rgba(0,255,0,0.5)"} # Hijau (Bullish)
|
| 186 |
+
],
|
| 187 |
+
'threshold': {
|
| 188 |
+
'line': {'color': "black", 'width': 4},
|
| 189 |
+
'thickness': 0.75,
|
| 190 |
+
'value': 0
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
))
|
| 194 |
+
|
| 195 |
+
fig.update_layout(
|
| 196 |
+
template='plotly_white',
|
| 197 |
+
height=300,
|
| 198 |
+
paper_bgcolor='white',
|
| 199 |
+
plot_bgcolor='white',
|
| 200 |
+
font=dict(color='black')
|
| 201 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
return fig, news_summary
|
| 204 |
|
| 205 |
except Exception as e:
|
| 206 |
+
# Return error plot (menggunakan Matplotlib untuk error fallback)
|
| 207 |
fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
|
| 208 |
fig.patch.set_facecolor('white')
|
| 209 |
ax.text(0.5, 0.5, f'Sentiment Error: {str(e)}', ha='center', va='center',
|
|
|
|
| 312 |
|
| 313 |
with gr.TabItem("Sentiment Analysis"):
|
| 314 |
with gr.Row():
|
| 315 |
+
sentiment_gauge = gr.Plot(label="Sentiment Score")
|
| 316 |
+
news_display = gr.HTML(label="Market News")
|
|
|
|
|
|
|
| 317 |
|
| 318 |
with gr.TabItem("Fundamentals"):
|
| 319 |
with gr.Row():
|