SHELLAPANDIANGANHUNGING commited on
Commit
b2cb83a
·
verified ·
1 Parent(s): fc2e3a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -1054,6 +1054,7 @@ try:
1054
  from wordcloud import WordCloud
1055
  import matplotlib.pyplot as plt
1056
  import plotly.express as px
 
1057
  WORDCLOUD_AVAILABLE = True
1058
  except ImportError:
1059
  WORDCLOUD_AVAILABLE = False
@@ -1073,19 +1074,43 @@ if WORDCLOUD_AVAILABLE:
1073
  # 2 Kolom
1074
  col1, col2 = st.columns(2)
1075
 
1076
- # === PIE CHART: Semua temuan_kategori ===
1077
  with col1:
1078
  if 'temuan_kategori' in df_all_kategori.columns:
1079
  # Hitung jumlah per kategori
1080
  category_counts = df_all_kategori['temuan_kategori'].value_counts()
1081
 
1082
  if not category_counts.empty:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1083
  # Buat pie chart
1084
  fig_pie = px.pie(
1085
  names=category_counts.index,
1086
  values=category_counts.values,
1087
  title="Distribution of All Issue Categories",
1088
- color_discrete_sequence=px.colors.sequential.Viridis
1089
  )
1090
  fig_pie.update_traces(textposition='inside', textinfo='percent+label')
1091
  fig_pie.update_layout(height=500)
@@ -1119,6 +1144,7 @@ if WORDCLOUD_AVAILABLE:
1119
 
1120
  # Output kecil tapi tajam
1121
  fig, ax = plt.subplots(figsize=(3, 2), dpi=200)
 
1122
  ax.imshow(wordcloud, interpolation='bilinear')
1123
  ax.axis('off')
1124
  plt.tight_layout()
 
1054
  from wordcloud import WordCloud
1055
  import matplotlib.pyplot as plt
1056
  import plotly.express as px
1057
+ import numpy as np
1058
  WORDCLOUD_AVAILABLE = True
1059
  except ImportError:
1060
  WORDCLOUD_AVAILABLE = False
 
1074
  # 2 Kolom
1075
  col1, col2 = st.columns(2)
1076
 
1077
+ # === PIE CHART: Semua temuan_kategori (Positive Hijau, Lainnya Merah Pastel) ===
1078
  with col1:
1079
  if 'temuan_kategori' in df_all_kategori.columns:
1080
  # Hitung jumlah per kategori
1081
  category_counts = df_all_kategori['temuan_kategori'].value_counts()
1082
 
1083
  if not category_counts.empty:
1084
+ # Buat warna custom
1085
+ colors = []
1086
+ for cat in category_counts.index:
1087
+ if cat == 'Positive':
1088
+ colors.append('#2E7D32') # Hijau
1089
+ else:
1090
+ # Gradasi merah pastel: dari gelap ke terang
1091
+ # Urutan: index 0 = terbanyak
1092
+ idx = list(category_counts.index).index(cat)
1093
+ # Misal: 0 → merah gelap, 1 → sedikit lebih terang, dst.
1094
+ # Gunakan indeks untuk gradasi
1095
+ total_non_positive = len([c for c in category_counts.index if c != 'Positive'])
1096
+ if total_non_positive > 0:
1097
+ # Buat gradasi dari merah gelap ke terang
1098
+ step = idx / max(1, total_non_positive - 1) if total_non_positive > 1 else 0
1099
+ # Rentang merah pastel: #c62828 ke #ffebee
1100
+ r = int(198 - (198 - 255) * step)
1101
+ g = int(40 - (40 - 235) * step)
1102
+ b = int(40 - (40 - 238) * step)
1103
+ color_hex = f"#{r:02x}{g:02x}{b:02x}"
1104
+ else:
1105
+ color_hex = "#c62828" # Default merah gelap
1106
+ colors.append(color_hex)
1107
+
1108
  # Buat pie chart
1109
  fig_pie = px.pie(
1110
  names=category_counts.index,
1111
  values=category_counts.values,
1112
  title="Distribution of All Issue Categories",
1113
+ color_discrete_sequence=colors
1114
  )
1115
  fig_pie.update_traces(textposition='inside', textinfo='percent+label')
1116
  fig_pie.update_layout(height=500)
 
1144
 
1145
  # Output kecil tapi tajam
1146
  fig, ax = plt.subplots(figsize=(3, 2), dpi=200)
1147
+ ax.set_title("Unsafe Issues", fontsize=10)
1148
  ax.imshow(wordcloud, interpolation='bilinear')
1149
  ax.axis('off')
1150
  plt.tight_layout()