Arif commited on
Commit
0d96540
·
1 Parent(s): 9581ef6

Updated app.py to version 7

Browse files
Files changed (1) hide show
  1. app.py +30 -28
app.py CHANGED
@@ -75,7 +75,8 @@ with tab1:
75
  st.subheader("❓ Ask AI About Your Data")
76
  question = st.text_input(
77
  "What would you like to know about this data?",
78
- placeholder="e.g., What is the average value in column X?"
 
79
  )
80
 
81
  if question:
@@ -123,39 +124,40 @@ with tab2:
123
  with st.chat_message(message["role"]):
124
  st.markdown(message["content"])
125
 
126
- # Chat input
127
- user_input = st.chat_input("Type your message here...")
 
 
 
 
128
 
129
  if user_input:
130
  # Add user message to history
131
  st.session_state.messages.append({"role": "user", "content": user_input})
132
 
133
- # Display user message
134
- with st.chat_message("user"):
135
- st.markdown(user_input)
136
-
137
  # Generate AI response
138
- with st.chat_message("assistant"):
139
- with st.spinner("⏳ Generating response..."):
140
- try:
141
- prompt = f"User: {user_input}\n\nAssistant:"
142
-
143
- response = client.text_generation(
144
- prompt,
145
- max_new_tokens=300,
146
- temperature=0.7,
147
- )
148
-
149
- assistant_message = response.strip()
150
- st.markdown(assistant_message)
151
-
152
- # Add assistant message to history
153
- st.session_state.messages.append({
154
- "role": "assistant",
155
- "content": assistant_message
156
- })
157
- except Exception as e:
158
- st.error(f"Error generating response: {e}")
 
159
 
160
  # ============================================================================
161
  # TAB 3: About
 
75
  st.subheader("❓ Ask AI About Your Data")
76
  question = st.text_input(
77
  "What would you like to know about this data?",
78
+ placeholder="e.g., What is the average value in column X?",
79
+ key="data_question"
80
  )
81
 
82
  if question:
 
124
  with st.chat_message(message["role"]):
125
  st.markdown(message["content"])
126
 
127
+ # Chat input - MUST be outside tabs, so we use text_input instead
128
+ user_input = st.text_input(
129
+ "Type your message:",
130
+ placeholder="Ask me anything...",
131
+ key="chat_input"
132
+ )
133
 
134
  if user_input:
135
  # Add user message to history
136
  st.session_state.messages.append({"role": "user", "content": user_input})
137
 
 
 
 
 
138
  # Generate AI response
139
+ with st.spinner("⏳ Generating response..."):
140
+ try:
141
+ prompt = f"User: {user_input}\n\nAssistant:"
142
+
143
+ response = client.text_generation(
144
+ prompt,
145
+ max_new_tokens=300,
146
+ temperature=0.7,
147
+ )
148
+
149
+ assistant_message = response.strip()
150
+
151
+ # Add assistant message to history
152
+ st.session_state.messages.append({
153
+ "role": "assistant",
154
+ "content": assistant_message
155
+ })
156
+
157
+ # Rerun to display the new messages
158
+ st.rerun()
159
+ except Exception as e:
160
+ st.error(f"Error generating response: {e}")
161
 
162
  # ============================================================================
163
  # TAB 3: About