omniverse1 commited on
Commit
8e38e51
·
verified ·
1 Parent(s): b08ac14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -40
app.py CHANGED
@@ -164,62 +164,44 @@ def analyze_sentiment(asset_name):
164
  """Analyze market sentiment for selected asset"""
165
  try:
166
  ticker = asset_map[asset_name]
167
- # FIX PENTING: PANGGILAN FUNGSI YANG BENAR
168
- sentiment_score, news_summary = sentiment_analyzer.analyze_market_sentiment(ticker)
169
 
170
- # --- Implementasi Matplotlib Gauge (Sesuai Gambar Referensi) ---
171
 
172
  # Create sentiment gauge using matplotlib
173
  fig, ax = plt.subplots(figsize=(6, 4), facecolor='white')
174
  fig.patch.set_facecolor('white')
175
 
176
  # Setup Gauge limits
177
- ax.set_xlim(-1.1, 1.1)
178
- ax.set_ylim(-0.2, 1.1)
179
  ax.set_aspect('equal')
180
 
181
- # Draw gauge background arc (light gray container)
182
  theta = np.linspace(np.pi, 0, 100)
183
  x, y = np.cos(theta), np.sin(theta)
184
 
185
- # Draw full light gray arc (Outer ring)
186
- ax.plot(x, y, color='lightgray', linewidth=10, solid_capstyle='round', zorder=1)
187
-
188
- # Segments (Matching the image)
189
- # 1. Red: -1.0 to -0.5
190
- ax.fill_between(x[75:], y[75:], 0, where=x[75:]<=-0.5, color='#F08080', alpha=0.9, linewidth=0, zorder=2)
191
- # 2. Yellow/Orange: -0.5 to 0.0
192
- ax.fill_between(x[50:75], y[50:75], 0, where=x[50:75]<0, color='#FFD700', alpha=0.9, linewidth=0, zorder=2)
193
- # 3. Light Gray: 0.0 to 0.5 (Neutral)
194
- ax.fill_between(x[25:50], y[25:50], 0, where=x[25:50]>0, color='#D3D3D3', alpha=0.9, linewidth=0, zorder=2)
195
- # 4. Light Green: 0.5 to 1.0
196
- ax.fill_between(x[:25], y[:25], 0, where=x[:25]>=0.5, color='#90EE90', alpha=0.9, linewidth=0, zorder=2)
197
-
198
 
199
- # Draw Needle (Pointer)
200
- needle_angle = np.pi * (1 - (sentiment_score + 1) / 2)
201
  needle_x = 0.8 * np.cos(needle_angle)
202
  needle_y = 0.8 * np.sin(needle_angle)
203
 
204
- # Draw the Yellow/Gold needle/pointer
205
- ax.plot([0, needle_x], [0, needle_y], color='gold', linewidth=6, solid_capstyle='round', zorder=5)
206
- # Draw the black cap on the arc (untuk tampilan jarum)
207
- ax.plot([needle_x], [needle_y], marker='|', color='black', markersize=15, markeredgewidth=2, zorder=6)
208
- # Center black point
209
- ax.plot([0], [0], marker='o', color='black', markersize=8, zorder=7)
210
 
211
- # Draw score number (seperti gambar)
212
  score_color = 'red' if sentiment_score < 0 else 'green' if sentiment_score > 0 else 'black'
213
-
214
- # Score label: e.g., -0.123 (Font besar di tengah)
215
- ax.text(0, -0.05, f"{sentiment_score:+.3f}", ha='center', va='center',
216
- fontsize=28, color=score_color, weight='bold', zorder=7)
217
-
218
- # Trend indicator (panah bawah/atas kecil di bawah skor)
219
- trend_arrow = '▲' if sentiment_score > 0.0 else '▼' if sentiment_score < 0.0 else ''
220
- # Text di bawah score (misalnya ▼-0.123)
221
- ax.text(0.0, -0.18, f"{trend_arrow}{abs(sentiment_score):.3f}", ha='center', va='center',
222
- fontsize=14, color=score_color, zorder=7)
223
 
224
  # Add labels for the scale
225
  ax.text(-1, 0, "-1", ha='center', va='top', fontsize=10, color='black')
@@ -346,8 +328,10 @@ with gr.Blocks(
346
 
347
  with gr.TabItem("Sentiment Analysis"):
348
  with gr.Row():
349
- sentiment_gauge = gr.Plot(label="Sentiment Score")
350
- news_display = gr.HTML(label="Market News")
 
 
351
 
352
  with gr.TabItem("Fundamentals"):
353
  with gr.Row():
 
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')
 
328
 
329
  with gr.TabItem("Sentiment Analysis"):
330
  with gr.Row():
331
+ with gr.Column(scale=1):
332
+ sentiment_gauge = gr.Plot(label="Sentiment Score")
333
+ with gr.Column(scale=1):
334
+ news_display = gr.HTML(label="Market News")
335
 
336
  with gr.TabItem("Fundamentals"):
337
  with gr.Row():