EditsPaarth commited on
Commit
39db6c7
·
verified ·
1 Parent(s): 52ec1c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -118,18 +118,28 @@ 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 and preview it with a table format
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) # Select top 10 rows for the preview
125
-
126
- # Create the textual prompt
 
 
 
127
  prompt = f"""
128
  The user has uploaded a dataset and selected the '{visualization_type}' visualization type with a class size of {class_size}.
129
  Below is a preview of the dataset:
 
 
 
 
 
 
130
  """
131
 
132
- return prompt, data_snippet
 
133
 
134
 
135
  # Streamlit App
@@ -156,15 +166,12 @@ if uploaded_file is not None:
156
  class_size = st.slider("Select the class size for certain plots (e.g., Histogram)", 5, 50, 10)
157
 
158
  # Perform Analysis and Visualization
159
- prompt, data_snippet = analyze_data(data, visualization_type, class_size)
160
 
161
- # Display the textual part of the prompt
162
  st.subheader("Prompt Sent to Groq")
163
- st.text(prompt)
164
-
165
- # Display the data preview as a table
166
- st.subheader("Preview of the Dataset (as Table)")
167
- st.table(data_snippet)
168
 
169
  # Chat with Groq Section
170
  st.subheader("Chat with Groq")
 
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
 
166
  class_size = st.slider("Select the class size for certain plots (e.g., Histogram)", 5, 50, 10)
167
 
168
  # Perform Analysis and Visualization
169
+ prompt = analyze_data(data, visualization_type, class_size)
170
 
171
+ # Display the textual prompt with the indented table
172
  st.subheader("Prompt Sent to Groq")
173
+ st.text_area("Preview of Prompt", value=prompt, height=300)
174
+
 
 
 
175
 
176
  # Chat with Groq Section
177
  st.subheader("Chat with Groq")