DrishtiSharma commited on
Commit
f07f50d
·
verified ·
1 Parent(s): ff78f1d

Update mylab/fixed_font_issue.py

Browse files
Files changed (1) hide show
  1. mylab/fixed_font_issue.py +42 -0
mylab/fixed_font_issue.py CHANGED
@@ -110,6 +110,48 @@ def ask_gpt4o_for_visualization(query, df, llm):
110
  st.error("⚠️ GPT-4o failed to generate a valid suggestion.")
111
  return None
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  # Function to create TXT file
115
  def create_text_report_with_viz_temp(report, conclusion, visualizations):
 
110
  st.error("⚠️ GPT-4o failed to generate a valid suggestion.")
111
  return None
112
 
113
+ # Dynamically generate Plotly visualizations based on GPT-4o suggestions
114
+ def generate_visualization(suggestion, df):
115
+ chart_type = suggestion.get("chart_type", "bar").lower()
116
+ x_axis = suggestion.get("x_axis")
117
+ y_axis = suggestion.get("y_axis")
118
+ group_by = suggestion.get("group_by")
119
+
120
+ # Ensure required inputs are available
121
+ if not x_axis or not y_axis:
122
+ st.warning("⚠️ GPT-4o did not provide enough information for the visualization.")
123
+ return None
124
+
125
+ # Dynamically select the Plotly function
126
+ plotly_function = getattr(px, chart_type, None)
127
+
128
+ # Handle unsupported chart types gracefully
129
+ if not plotly_function:
130
+ st.warning(f"⚠️ Unsupported chart type '{chart_type}' suggested by GPT-4o.")
131
+ return None
132
+
133
+ # Prepare dynamic parameters for Plotly function
134
+ plot_args = {
135
+ "data_frame": df,
136
+ "x": x_axis,
137
+ "y": y_axis,
138
+ }
139
+ if group_by:
140
+ plot_args["color"] = group_by
141
+
142
+ try:
143
+ # Generate the dynamic visualization
144
+ fig = plotly_function(**plot_args)
145
+ fig.update_layout(
146
+ title=f"{chart_type.title()} Plot of {y_axis.replace('_', ' ').title()} by {x_axis.replace('_', ' ').title()}",
147
+ xaxis_title=x_axis.replace('_', ' ').title(),
148
+ yaxis_title=y_axis.replace('_', ' ').title(),
149
+ )
150
+ return fig
151
+
152
+ except Exception as e:
153
+ st.error(f"⚠️ Failed to generate visualization: {e}")
154
+ return None
155
 
156
  # Function to create TXT file
157
  def create_text_report_with_viz_temp(report, conclusion, visualizations):