Spaces:
Build error
Build error
Upload 4 files
Browse files- app.py +14 -7
- prompt_models.py +15 -9
app.py
CHANGED
|
@@ -173,13 +173,20 @@ with col1a:
|
|
| 173 |
|
| 174 |
with st.spinner("Thinking..."):
|
| 175 |
if "df" in st.session_state:
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
st.
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
else:
|
| 184 |
st.write('You need to upload the data first')
|
| 185 |
|
|
|
|
| 173 |
|
| 174 |
with st.spinner("Thinking..."):
|
| 175 |
if "df" in st.session_state:
|
| 176 |
+
try:
|
| 177 |
+
df = st.session_state.df
|
| 178 |
+
columns = df.columns
|
| 179 |
+
shape = df.shape
|
| 180 |
+
dtypes = df.dtypes
|
| 181 |
+
response = text_llm(prompt_chatbot(user_query,st.session_state.df.columns, st.session_state.df.shape, st.session_state.df.dtypes))
|
| 182 |
+
clean_response = re.sub(r'<\s*think\s*>.*?<\s*/\s*think\s*>', '', response, flags=re.DOTALL | re.IGNORECASE)
|
| 183 |
+
|
| 184 |
+
# show and save chatbot response
|
| 185 |
+
with st.chat_message("assistant"):
|
| 186 |
+
st.markdown(clean_response)
|
| 187 |
+
st.session_state.chatbot['chat_history'].append({"role": "assistant", "content": clean_response})
|
| 188 |
+
except AttributeError as e:
|
| 189 |
+
st.error(f"Atribut DataFrame tidak lengkap: {e}")
|
| 190 |
else:
|
| 191 |
st.write('You need to upload the data first')
|
| 192 |
|
prompt_models.py
CHANGED
|
@@ -50,6 +50,7 @@ def generate_prompt(user_input, df_columns):
|
|
| 50 |
df['Predict data'] = model.predict(X)
|
| 51 |
|
| 52 |
4. OUTPUT HANDLING:
|
|
|
|
| 53 |
- Untuk hasil non-kolom (skalar/matriks/agregat):
|
| 54 |
print("\\nHasil analisis:")
|
| 55 |
print(result)
|
|
@@ -113,7 +114,7 @@ def generate_prompt(user_input, df_columns):
|
|
| 113 |
)
|
| 114 |
|
| 115 |
# Contoh pie chart
|
| 116 |
-
#
|
| 117 |
feedback_counts = df[feedback_col].value_counts().reset_index()
|
| 118 |
feedback_counts.columns = [feedback_col, 'count']
|
| 119 |
|
|
@@ -121,7 +122,7 @@ def generate_prompt(user_input, df_columns):
|
|
| 121 |
print("\nFeedback counts:")
|
| 122 |
print(feedback_counts)
|
| 123 |
|
| 124 |
-
#
|
| 125 |
fig = px.pie(
|
| 126 |
feedback_counts,
|
| 127 |
names=feedback_col,
|
|
@@ -130,22 +131,27 @@ def generate_prompt(user_input, df_columns):
|
|
| 130 |
title='Feedback Distribution'
|
| 131 |
)
|
| 132 |
|
| 133 |
-
#
|
| 134 |
-
max_segment = feedback_counts[feedback_counts['count']
|
| 135 |
pull = [0.2 if feedback == max_segment else 0 for feedback in feedback_counts[feedback_col]]
|
| 136 |
|
| 137 |
-
# Update traces
|
| 138 |
fig.update_traces(
|
| 139 |
-
pull=pull
|
|
|
|
|
|
|
| 140 |
)
|
| 141 |
|
| 142 |
-
# Update layout
|
| 143 |
fig.update_layout(
|
| 144 |
margin=dict(t=50, b=50, l=50, r=50),
|
| 145 |
-
title_x=0.5
|
|
|
|
|
|
|
|
|
|
| 146 |
)
|
| 147 |
|
| 148 |
-
#
|
| 149 |
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
|
| 150 |
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
|
| 151 |
|
|
|
|
| 50 |
df['Predict data'] = model.predict(X)
|
| 51 |
|
| 52 |
4. OUTPUT HANDLING:
|
| 53 |
+
Selalu cek kode untuk plot agar tidak muncul error "cannot reindex on an axis with duplicate labels"
|
| 54 |
- Untuk hasil non-kolom (skalar/matriks/agregat):
|
| 55 |
print("\\nHasil analisis:")
|
| 56 |
print(result)
|
|
|
|
| 114 |
)
|
| 115 |
|
| 116 |
# Contoh pie chart
|
| 117 |
+
# Hitung jumlah feedback
|
| 118 |
feedback_counts = df[feedback_col].value_counts().reset_index()
|
| 119 |
feedback_counts.columns = [feedback_col, 'count']
|
| 120 |
|
|
|
|
| 122 |
print("\nFeedback counts:")
|
| 123 |
print(feedback_counts)
|
| 124 |
|
| 125 |
+
# Buat pie chart untuk feedback
|
| 126 |
fig = px.pie(
|
| 127 |
feedback_counts,
|
| 128 |
names=feedback_col,
|
|
|
|
| 131 |
title='Feedback Distribution'
|
| 132 |
)
|
| 133 |
|
| 134 |
+
# Tentukan segmen terbesar dengan cara yang lebih aman
|
| 135 |
+
max_segment = feedback_counts.loc[feedback_counts['count'].idxmax(), feedback_col]
|
| 136 |
pull = [0.2 if feedback == max_segment else 0 for feedback in feedback_counts[feedback_col]]
|
| 137 |
|
| 138 |
+
# Update traces untuk menarik segmen terbesar
|
| 139 |
fig.update_traces(
|
| 140 |
+
pull=pull,
|
| 141 |
+
textinfo='percent+label', # Menampilkan persentase dan label
|
| 142 |
+
marker=dict(line=dict(color='#000000', width=1)) # Garis tepi untuk tiap segmen
|
| 143 |
)
|
| 144 |
|
| 145 |
+
# Update layout untuk visualisasi yang lebih baik
|
| 146 |
fig.update_layout(
|
| 147 |
margin=dict(t=50, b=50, l=50, r=50),
|
| 148 |
+
title_x=0.5,
|
| 149 |
+
legend_title_text='Kategori Feedback', # Judul legend
|
| 150 |
+
uniformtext_minsize=12, # Ukuran teks minimal
|
| 151 |
+
uniformtext_mode='hide' # Sembunyikan teks yang tidak cukup space
|
| 152 |
)
|
| 153 |
|
| 154 |
+
# Tambahkan border ke chart
|
| 155 |
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
|
| 156 |
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
|
| 157 |
|