EditsPaarth commited on
Commit
631b613
·
verified ·
1 Parent(s): 4dfc630

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -118,30 +118,40 @@ def analyze_data(data, visualization_type, class_size=10):
118
  prompt = generate_groq_prompt(data, visualization_type, class_size)
119
  return prompt
120
 
121
- # Function to generate a prompt with an indented table
122
  def generate_groq_prompt(data, visualization_type, class_size):
123
  # Limit the preview to the first 10 rows for readability
124
- data_snippet = data.head(10)
125
 
126
- # Convert the data to a string table format with proper indentation
127
- table_string = data_snippet.to_markdown(index=False, tablefmt="grid")
128
 
129
- # Create the prompt text with the table included
 
 
 
 
 
 
 
 
 
 
 
 
130
  prompt = f"""
131
  The user has uploaded a dataset and selected the '{visualization_type}' visualization type with a class size of {class_size}.
132
  Below is a preview of the dataset:
133
 
134
- ```
135
- {table_string}
136
- ```
137
 
138
- Please generate Python code that achieves the requested visualization. For data, please write it directly in the code rather than using file input.
139
  """
140
 
141
  return prompt
142
 
143
 
144
 
 
145
  # Streamlit App
146
  st.title("Data Analysis AI")
147
  st.markdown("Upload a file (CSV or Excel) to analyze it.")
 
118
  prompt = generate_groq_prompt(data, visualization_type, class_size)
119
  return prompt
120
 
 
121
  def generate_groq_prompt(data, visualization_type, class_size):
122
  # Limit the preview to the first 10 rows for readability
123
+ data_snippet = data.head(10) # Select top 10 rows for the preview
124
 
125
+ # Compute column widths for alignment
126
+ column_widths = [max(len(str(val)) for val in [col] + data_snippet[col].tolist()) for col in data_snippet.columns]
127
 
128
+ # Create the table header with spacing
129
+ table_header = " ".join(f"{col:<{column_widths[i]}}" for i, col in enumerate(data_snippet.columns))
130
+
131
+ # Create the rows with spacing
132
+ table_rows = "\n".join(
133
+ " " + " ".join(f"{str(val):<{column_widths[i]}}" for i, val in enumerate(row)) # Add indentation
134
+ for row in data_snippet.values
135
+ )
136
+
137
+ # Combine header and rows into a single table
138
+ formatted_table = f" {table_header}\n{table_rows}"
139
+
140
+ # Create the textual prompt
141
  prompt = f"""
142
  The user has uploaded a dataset and selected the '{visualization_type}' visualization type with a class size of {class_size}.
143
  Below is a preview of the dataset:
144
 
145
+ {formatted_table}
 
 
146
 
147
+ Please generate Python code for the analysis and visualization specified.
148
  """
149
 
150
  return prompt
151
 
152
 
153
 
154
+
155
  # Streamlit App
156
  st.title("Data Analysis AI")
157
  st.markdown("Upload a file (CSV or Excel) to analyze it.")