naveenseth commited on
Commit
41bce61
·
verified ·
1 Parent(s): e9fdec1

Changes made

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -128,8 +128,13 @@ def append_to_excel(file_path: str, data: dict):
128
  # Prepare datasets for SmartDatalake
129
  if uploaded_files:
130
  dataframes = []
 
 
 
 
131
  for uploaded_file in uploaded_files:
132
  try:
 
133
  if uploaded_file.name.endswith('.csv'):
134
  df = pd.read_csv(uploaded_file)
135
  elif uploaded_file.name.endswith('.xlsx'):
@@ -139,10 +144,12 @@ if uploaded_files:
139
  continue
140
 
141
  dataframes.append(df) # Collect DataFrames
142
- success_message = st.success(f"File '{uploaded_file.name}' successfully loaded.")
143
- time.sleep(2) # Keep the message for 2 seconds
144
- success_message.empty() # Remove the message after 2 seconds
145
 
 
 
 
 
 
146
  except Exception as e:
147
  st.error(f"Error loading file '{uploaded_file.name}': {e}")
148
 
@@ -158,7 +165,6 @@ both general and specific to uploaded Excel files. Your goal is to assist users
158
  understanding market trends, and making data-driven decisions. You should always be insightful, professional, and proactive in offering valuable recommendations and
159
  provide a clear and formatted response for the following query. Include spaces between sentences and highlight key points clearly{user_query}'''
160
 
161
- # Handle user queries
162
  # Handle user queries
163
  if temp_query:
164
  with st.spinner("Thinking..."):
@@ -172,7 +178,6 @@ if temp_query:
172
  append_to_excel(EXCEL_FILE_PATH, track)
173
 
174
  # Update chat history with the AI response
175
- chat_added = False
176
  for chat in st.session_state['chat_history']:
177
  if chat["query"] == temp_query:
178
  # If the response is a file path (i.e., a chart), just store "Generated chart"
@@ -180,16 +185,8 @@ if temp_query:
180
  chat["response"] = "Generated chart" # Store only the message, not the file path
181
  else:
182
  chat["response"] = response # Store the normal text response
183
- chat_added = True
184
  break
185
 
186
- if not chat_added:
187
- # If the query is not found, add it to the chat history
188
- if isinstance(response, str) and os.path.exists(response):
189
- st.session_state['chat_history'].append({"query": temp_query, "response": "Generated chart"})
190
- else:
191
- st.session_state['chat_history'].append({"query": temp_query, "response": response})
192
-
193
  # Handle the response (image or text)
194
  if isinstance(response, str) and os.path.exists(response):
195
  st.image(response, caption="Generated Chart")
 
128
  # Prepare datasets for SmartDatalake
129
  if uploaded_files:
130
  dataframes = []
131
+ # Show success message only once during file upload process
132
+ if 'success_message_shown' not in st.session_state:
133
+ st.session_state.success_message_shown = False
134
+
135
  for uploaded_file in uploaded_files:
136
  try:
137
+ # Read the file based on its extension
138
  if uploaded_file.name.endswith('.csv'):
139
  df = pd.read_csv(uploaded_file)
140
  elif uploaded_file.name.endswith('.xlsx'):
 
144
  continue
145
 
146
  dataframes.append(df) # Collect DataFrames
 
 
 
147
 
148
+ # Show success message only once for each file
149
+ if not st.session_state.success_message_shown:
150
+ st.session_state.success_message_shown = True
151
+ st.success(f"File '{uploaded_file.name}' successfully loaded.")
152
+
153
  except Exception as e:
154
  st.error(f"Error loading file '{uploaded_file.name}': {e}")
155
 
 
165
  understanding market trends, and making data-driven decisions. You should always be insightful, professional, and proactive in offering valuable recommendations and
166
  provide a clear and formatted response for the following query. Include spaces between sentences and highlight key points clearly{user_query}'''
167
 
 
168
  # Handle user queries
169
  if temp_query:
170
  with st.spinner("Thinking..."):
 
178
  append_to_excel(EXCEL_FILE_PATH, track)
179
 
180
  # Update chat history with the AI response
 
181
  for chat in st.session_state['chat_history']:
182
  if chat["query"] == temp_query:
183
  # If the response is a file path (i.e., a chart), just store "Generated chart"
 
185
  chat["response"] = "Generated chart" # Store only the message, not the file path
186
  else:
187
  chat["response"] = response # Store the normal text response
 
188
  break
189
 
 
 
 
 
 
 
 
190
  # Handle the response (image or text)
191
  if isinstance(response, str) and os.path.exists(response):
192
  st.image(response, caption="Generated Chart")