Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1059,6 +1059,7 @@ with col_3d:
|
|
| 1059 |
|
| 1060 |
####OBJECTIVE 4
|
| 1061 |
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
|
|
|
| 1062 |
try:
|
| 1063 |
from wordcloud import WordCloud
|
| 1064 |
import matplotlib.pyplot as plt
|
|
@@ -1081,14 +1082,14 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1081 |
col_wc1 = st.columns(1)
|
| 1082 |
|
| 1083 |
# === FUNCTION: GENERATE HIGH QUALITY WORDCLOUD ===
|
| 1084 |
-
def generate_wordcloud(text_data,
|
| 1085 |
|
| 1086 |
if text_data is None or text_data.empty:
|
| 1087 |
-
col.warning(
|
| 1088 |
return
|
| 1089 |
|
| 1090 |
if text_data.isna().all():
|
| 1091 |
-
col.warning(
|
| 1092 |
return
|
| 1093 |
|
| 1094 |
# Gabungkan text
|
|
@@ -1097,12 +1098,12 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1097 |
text = re.sub(r'[^a-zA-Z\s]', ' ', text)
|
| 1098 |
|
| 1099 |
if not text.strip():
|
| 1100 |
-
col.warning(
|
| 1101 |
return
|
| 1102 |
|
| 1103 |
# === HIGH RESOLUTION WORDCLOUD ===
|
| 1104 |
wordcloud = WordCloud(
|
| 1105 |
-
width=1600, # resolusi besar
|
| 1106 |
height=800,
|
| 1107 |
background_color='white',
|
| 1108 |
colormap='viridis',
|
|
@@ -1110,10 +1111,10 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1110 |
random_state=42
|
| 1111 |
).generate(text)
|
| 1112 |
|
| 1113 |
-
|
|
|
|
| 1114 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 1115 |
ax.axis('off')
|
| 1116 |
-
ax.set_title(title, fontsize=16)
|
| 1117 |
plt.tight_layout()
|
| 1118 |
|
| 1119 |
col.pyplot(fig, use_container_width=True)
|
|
@@ -1121,7 +1122,7 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1121 |
# === CALL WORDCLOUD ===
|
| 1122 |
with col_wc1[0]:
|
| 1123 |
if 'keyword_kategori' in df_filtered_kategori.columns:
|
| 1124 |
-
generate_wordcloud(df_filtered_kategori['keyword_kategori'],
|
| 1125 |
col_wc1[0])
|
| 1126 |
else:
|
| 1127 |
col_wc1[0].warning("Column 'keyword_kategori' not available.")
|
|
@@ -1129,6 +1130,7 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1129 |
else:
|
| 1130 |
st.info("WordCloud library not installed. Install `wordcloud` and `matplotlib` to enable this feature.")
|
| 1131 |
|
|
|
|
| 1132 |
# =================== 5. Matrix (Tetap Dipertahankan) ===================
|
| 1133 |
st.markdown("<h3 class='section-title'>OBJECTIVE 5 - Findings vs Lead Time: Which Companies Move Slow?</h3>", unsafe_allow_html=True)
|
| 1134 |
|
|
|
|
| 1059 |
|
| 1060 |
####OBJECTIVE 4
|
| 1061 |
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1062 |
+
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1063 |
try:
|
| 1064 |
from wordcloud import WordCloud
|
| 1065 |
import matplotlib.pyplot as plt
|
|
|
|
| 1082 |
col_wc1 = st.columns(1)
|
| 1083 |
|
| 1084 |
# === FUNCTION: GENERATE HIGH QUALITY WORDCLOUD ===
|
| 1085 |
+
def generate_wordcloud(text_data, col):
|
| 1086 |
|
| 1087 |
if text_data is None or text_data.empty:
|
| 1088 |
+
col.warning("No data available for WordCloud.")
|
| 1089 |
return
|
| 1090 |
|
| 1091 |
if text_data.isna().all():
|
| 1092 |
+
col.warning("All data is NaN.")
|
| 1093 |
return
|
| 1094 |
|
| 1095 |
# Gabungkan text
|
|
|
|
| 1098 |
text = re.sub(r'[^a-zA-Z\s]', ' ', text)
|
| 1099 |
|
| 1100 |
if not text.strip():
|
| 1101 |
+
col.warning("No valid text remaining after cleaning.")
|
| 1102 |
return
|
| 1103 |
|
| 1104 |
# === HIGH RESOLUTION WORDCLOUD ===
|
| 1105 |
wordcloud = WordCloud(
|
| 1106 |
+
width=1600, # resolusi besar agar HD
|
| 1107 |
height=800,
|
| 1108 |
background_color='white',
|
| 1109 |
colormap='viridis',
|
|
|
|
| 1111 |
random_state=42
|
| 1112 |
).generate(text)
|
| 1113 |
|
| 1114 |
+
# === SMALL BUT SHARP OUTPUT ===
|
| 1115 |
+
fig, ax = plt.subplots(figsize=(4, 2), dpi=200)
|
| 1116 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 1117 |
ax.axis('off')
|
|
|
|
| 1118 |
plt.tight_layout()
|
| 1119 |
|
| 1120 |
col.pyplot(fig, use_container_width=True)
|
|
|
|
| 1122 |
# === CALL WORDCLOUD ===
|
| 1123 |
with col_wc1[0]:
|
| 1124 |
if 'keyword_kategori' in df_filtered_kategori.columns:
|
| 1125 |
+
generate_wordcloud(df_filtered_kategori['keyword_kategori'],
|
| 1126 |
col_wc1[0])
|
| 1127 |
else:
|
| 1128 |
col_wc1[0].warning("Column 'keyword_kategori' not available.")
|
|
|
|
| 1130 |
else:
|
| 1131 |
st.info("WordCloud library not installed. Install `wordcloud` and `matplotlib` to enable this feature.")
|
| 1132 |
|
| 1133 |
+
|
| 1134 |
# =================== 5. Matrix (Tetap Dipertahankan) ===================
|
| 1135 |
st.markdown("<h3 class='section-title'>OBJECTIVE 5 - Findings vs Lead Time: Which Companies Move Slow?</h3>", unsafe_allow_html=True)
|
| 1136 |
|