DrishtiSharma commited on
Commit
f615ebf
·
verified ·
1 Parent(s): 8fcfa20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -92,9 +92,14 @@ def load_dataset_into_session():
92
  # Streamlit app main
93
  st.title("ChatCSV powered by LLM")
94
 
 
95
  if "df" not in st.session_state:
96
  st.session_state.df = pd.DataFrame()
97
 
 
 
 
 
98
  st.header("Load Your Dataset")
99
  load_dataset_into_session()
100
 
@@ -104,13 +109,15 @@ if "df" in st.session_state and not st.session_state.df.empty:
104
  st.dataframe(st.session_state.df.head(num_rows))
105
 
106
  st.subheader("Chat with Your Dataset")
107
- user_query = st.text_area("Enter your query:")
108
-
 
 
109
  if st.button("Run Query"):
110
- if user_query.strip():
111
  with st.spinner("Processing your query..."):
112
  try:
113
- result = chat_with_csv(st.session_state.df, user_query)
114
  st.success(result)
115
  except Exception as e:
116
  st.error(f"Error processing your query: {e}")
 
92
  # Streamlit app main
93
  st.title("ChatCSV powered by LLM")
94
 
95
+ # Ensure session state for dataframe
96
  if "df" not in st.session_state:
97
  st.session_state.df = pd.DataFrame()
98
 
99
+ # Ensure session state for user query
100
+ if "user_query" not in st.session_state:
101
+ st.session_state.user_query = ""
102
+
103
  st.header("Load Your Dataset")
104
  load_dataset_into_session()
105
 
 
109
  st.dataframe(st.session_state.df.head(num_rows))
110
 
111
  st.subheader("Chat with Your Dataset")
112
+
113
+ # Text area for user query with session state persistence
114
+ st.session_state.user_query = st.text_area("Enter your query:", value=st.session_state.user_query)
115
+
116
  if st.button("Run Query"):
117
+ if st.session_state.user_query.strip():
118
  with st.spinner("Processing your query..."):
119
  try:
120
+ result = chat_with_csv(st.session_state.df, st.session_state.user_query)
121
  st.success(result)
122
  except Exception as e:
123
  st.error(f"Error processing your query: {e}")