Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -163,38 +163,55 @@ def create_chart_analysis(interval, asset_name):
|
|
| 163 |
def analyze_sentiment(asset_name):
|
| 164 |
"""Analyze market sentiment for selected asset"""
|
| 165 |
try:
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
# Create sentiment gauge using matplotlib
|
| 169 |
fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
|
| 170 |
fig.patch.set_facecolor('white')
|
| 171 |
|
| 172 |
-
#
|
| 173 |
-
ax.set_xlim(-1.
|
| 174 |
-
ax.set_ylim(0, 1)
|
| 175 |
ax.set_aspect('equal')
|
| 176 |
|
| 177 |
-
# Draw gauge background
|
| 178 |
theta = np.linspace(np.pi, 0, 100)
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
#
|
| 182 |
-
ax.fill_between(
|
| 183 |
-
|
| 184 |
-
ax.fill_between(
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
# Draw needle
|
| 190 |
-
needle_angle = np.pi * (1 - (sentiment_score + 1) / 2)
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
#
|
| 195 |
-
ax.
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
# Remove axes
|
| 200 |
ax.axis('off')
|
|
|
|
| 163 |
def analyze_sentiment(asset_name):
|
| 164 |
"""Analyze market sentiment for selected asset"""
|
| 165 |
try:
|
| 166 |
+
ticker = asset_map[asset_name]
|
| 167 |
+
sentiment_score, news_summary = sentiment_analyzer.analyze_sentiment(ticker)
|
| 168 |
+
|
| 169 |
+
# --- Modifikasi untuk tampilan Gauge yang lebih baik ---
|
| 170 |
|
| 171 |
# Create sentiment gauge using matplotlib
|
| 172 |
fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
|
| 173 |
fig.patch.set_facecolor('white')
|
| 174 |
|
| 175 |
+
# Setup Gauge limits
|
| 176 |
+
ax.set_xlim(-1.1, 1.1) # Diperluas sedikit untuk label
|
| 177 |
+
ax.set_ylim(-0.2, 1.1) # Diperluas sedikit ke bawah untuk skor
|
| 178 |
ax.set_aspect('equal')
|
| 179 |
|
| 180 |
+
# Draw gauge background segments
|
| 181 |
theta = np.linspace(np.pi, 0, 100)
|
| 182 |
+
x, y = np.cos(theta), np.sin(theta)
|
| 183 |
+
|
| 184 |
+
# Segments: Red (-1.0 to -0.5), Gray/Yellow (-0.5 to 0.5), Green (0.5 to 1.0)
|
| 185 |
+
ax.fill_between(x[75:], y[75:], 0, where=x[75:]<=-0.5, color='#F08080', alpha=0.9, linewidth=0) # Red (Bearish)
|
| 186 |
+
ax.fill_between(x[25:75], y[25:75], 0, color='#D3D3D3', alpha=0.9, linewidth=0) # Gray (Neutral)
|
| 187 |
+
ax.fill_between(x[:25], y[:25], 0, where=x[:25]>=0.5, color='#90EE90', alpha=0.9, linewidth=0) # Green (Bullish)
|
| 188 |
+
|
| 189 |
+
# Draw main arc line
|
| 190 |
+
ax.plot(x, y, color='#D3D3D3', linewidth=10, solid_capstyle='round', zorder=1)
|
| 191 |
+
|
| 192 |
+
# Draw needle (using a small triangle/arrow)
|
| 193 |
+
needle_angle = np.pi * (1 - (sentiment_score + 1) / 2) # Angle from pi (180 deg) to 0 (0 deg)
|
| 194 |
+
needle_x = 0.8 * np.cos(needle_angle)
|
| 195 |
+
needle_y = 0.8 * np.sin(needle_angle)
|
| 196 |
+
|
| 197 |
+
# Draw a line/needle for the pointer
|
| 198 |
+
ax.plot([0, needle_x], [0, needle_y], color='black', linewidth=3, zorder=3)
|
| 199 |
+
ax.plot([0], [0], marker='o', color='black', markersize=6, zorder=4)
|
| 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')
|