Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,8 +87,6 @@ if st.session_state.df is not None and st.session_state.show_preview:
|
|
| 87 |
st.dataframe(st.session_state.df.head())
|
| 88 |
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
"""def ask_gpt4o_for_visualization(query, df, llm):
|
| 93 |
columns = ', '.join(df.columns)
|
| 94 |
prompt = f"""
|
|
@@ -187,7 +185,21 @@ def ask_gpt4o_for_visualization(query, df, llm, retries=2):
|
|
| 187 |
if all(k in suggestions for k in ["chart_type", "x_axis", "y_axis"]):
|
| 188 |
return [suggestions]
|
| 189 |
else:
|
| 190 |
-
st.warning("β οΈ GPT-4o's suggestion is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
def add_stats_to_figure(fig, df, y_axis, chart_type):
|
|
|
|
| 87 |
st.dataframe(st.session_state.df.head())
|
| 88 |
|
| 89 |
|
|
|
|
|
|
|
| 90 |
"""def ask_gpt4o_for_visualization(query, df, llm):
|
| 91 |
columns = ', '.join(df.columns)
|
| 92 |
prompt = f"""
|
|
|
|
| 185 |
if all(k in suggestions for k in ["chart_type", "x_axis", "y_axis"]):
|
| 186 |
return [suggestions]
|
| 187 |
else:
|
| 188 |
+
st.warning("β οΈ GPT-4o's suggestion is incomplete.")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
except json.JSONDecodeError:
|
| 192 |
+
st.warning(f"β οΈ Attempt {attempt + 1}: GPT-4o returned invalid JSON.")
|
| 193 |
+
except Exception as e:
|
| 194 |
+
st.error(f"β οΈ Error during GPT-4o call: {e}")
|
| 195 |
+
|
| 196 |
+
# Retry if necessary
|
| 197 |
+
if attempt < retries:
|
| 198 |
+
st.info("π Retrying visualization suggestion...")
|
| 199 |
+
|
| 200 |
+
st.error("β Failed to generate a valid visualization after multiple attempts.")
|
| 201 |
+
return None
|
| 202 |
+
|
| 203 |
|
| 204 |
|
| 205 |
def add_stats_to_figure(fig, df, y_axis, chart_type):
|