Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from model_handler import ModelHandler
|
|
| 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,39 +165,66 @@ def analyze_sentiment(asset_name):
|
|
| 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 (
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
fig = go.Figure(go.Indicator(
|
| 174 |
-
mode="gauge+number
|
| 175 |
value=sentiment_score,
|
| 176 |
domain={'x': [0, 1], 'y': [0, 1]},
|
| 177 |
-
title={'text': f"{ticker} Market Sentiment (Simulated)"},
|
| 178 |
-
|
|
|
|
| 179 |
gauge={
|
| 180 |
-
'axis': {'range': [-1, 1]},
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
'steps': [
|
| 183 |
-
{'range': [-1, -0.5], 'color': "rgba(255,
|
| 184 |
-
{'range': [-0.5, 0
|
| 185 |
-
{'range': [0.5
|
|
|
|
| 186 |
],
|
|
|
|
|
|
|
| 187 |
'threshold': {
|
| 188 |
-
'line': {'color':
|
| 189 |
'thickness': 0.75,
|
| 190 |
-
'value':
|
| 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
|
|
|
|
| 9 |
from trading_logic import TradingLogic
|
| 10 |
import io
|
| 11 |
import base64
|
| 12 |
+
import plotly.graph_objects as go # <--- TAMBAHAN INI
|
| 13 |
|
| 14 |
# Global instances
|
| 15 |
data_processor = DataProcessor()
|
|
|
|
| 165 |
"""Analyze market sentiment for selected asset"""
|
| 166 |
try:
|
| 167 |
ticker = asset_map[asset_name]
|
|
|
|
| 168 |
sentiment_score, news_summary = sentiment_analyzer.analyze_market_sentiment(ticker)
|
| 169 |
|
| 170 |
+
# --- Implementasi Plotly Gauge (Disesuaikan agar mirip gambar) ---
|
| 171 |
|
| 172 |
+
# Warna berdasarkan Ticker (dari sentiment_analyzer.py)
|
| 173 |
+
if ticker == "BTC-USD":
|
| 174 |
+
bar_color = "#FFA500" # Orange
|
| 175 |
+
pointer_color = "black"
|
| 176 |
+
else: # GC=F
|
| 177 |
+
bar_color = "#FFD700" # Gold
|
| 178 |
+
pointer_color = "black"
|
| 179 |
+
|
| 180 |
+
# Tentukan warna teks skor
|
| 181 |
+
score_color = 'red' if sentiment_score < 0 else 'green' if sentiment_score > 0 else 'black'
|
| 182 |
+
|
| 183 |
fig = go.Figure(go.Indicator(
|
| 184 |
+
mode="gauge+number",
|
| 185 |
value=sentiment_score,
|
| 186 |
domain={'x': [0, 1], 'y': [0, 1]},
|
| 187 |
+
title={'text': f"{ticker} Market Sentiment (Simulated)", 'font': {'size': 20, 'color': 'black'}},
|
| 188 |
+
# Delta dihapus agar tidak muncul panah di bawah skor, skor utama yang diubah warnanya
|
| 189 |
+
|
| 190 |
gauge={
|
| 191 |
+
'axis': {'range': [-1, 1], 'tickwidth': 1, 'tickcolor': "black"},
|
| 192 |
+
|
| 193 |
+
# JANGAN menggunakan bar color, kita menggunakan threshold dan steps untuk jarum
|
| 194 |
+
'bar': {'color': "rgba(0,0,0,0)"}, # Bar dibuat transparan agar terlihat segmen
|
| 195 |
+
|
| 196 |
+
# Steps (Segments)
|
| 197 |
'steps': [
|
| 198 |
+
{'range': [-1, -0.5], 'color': "rgba(255, 99, 71, 1.0)"}, # Merah (Bearish kuat)
|
| 199 |
+
{'range': [-0.5, 0], 'color': "rgba(255, 223, 0, 1.0)"}, # Kuning (Bearish/Netral lemah)
|
| 200 |
+
{'range': [0, 0.5], 'color': "rgba(211, 211, 211, 1.0)"}, # Abu-abu (Netral/Bullish lemah)
|
| 201 |
+
{'range': [0.5, 1], 'color': "rgba(144, 238, 144, 1.0)"} # Hijau (Bullish kuat)
|
| 202 |
],
|
| 203 |
+
|
| 204 |
+
# Threshold digunakan untuk jarum/pointer
|
| 205 |
'threshold': {
|
| 206 |
+
'line': {'color': pointer_color, 'width': 3},
|
| 207 |
'thickness': 0.75,
|
| 208 |
+
'value': sentiment_score
|
| 209 |
+
},
|
| 210 |
+
|
| 211 |
+
# Outline diubah menjadi abu-abu
|
| 212 |
+
'bgcolor': "lightgray",
|
| 213 |
+
'bordercolor': "lightgray",
|
| 214 |
+
'borderwidth': 1
|
| 215 |
+
},
|
| 216 |
+
# Format Angka (mengganti warna angka utama)
|
| 217 |
+
number={'font': {'color': score_color, 'size': 50}, 'valueformat': '.3f'}
|
| 218 |
))
|
| 219 |
|
| 220 |
fig.update_layout(
|
| 221 |
template='plotly_white',
|
| 222 |
height=300,
|
| 223 |
+
# Mengganti warna background menjadi putih untuk menyatu dengan Gradio
|
| 224 |
paper_bgcolor='white',
|
| 225 |
plot_bgcolor='white',
|
| 226 |
+
font=dict(color='black'),
|
| 227 |
+
margin=dict(l=10, r=10, t=50, b=10)
|
| 228 |
)
|
| 229 |
|
| 230 |
return fig, news_summary
|