Arif commited on
Commit
ca37c17
Β·
1 Parent(s): e3d2b77

Updated app.py v11

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -12,10 +12,9 @@ st.set_page_config(
12
  st.title("πŸ“Š LLM Data Analyzer")
13
  st.write("*Analyze data and chat with AI - Powered by Hugging Face Spaces*")
14
 
15
- # Simple AI responses without API calls (fallback mode)
16
  def get_ai_response(prompt):
17
  """Generate simple AI-like responses without external API"""
18
- # Since HF APIs require auth, we'll use simple pattern matching
19
  prompt_lower = prompt.lower()
20
 
21
  # Data analysis responses
@@ -91,10 +90,9 @@ with tab1:
91
  )
92
 
93
  if question:
94
- with st.spinner("πŸ€” Analyzing your data..."):
95
- response = get_ai_response(question)
96
- st.success("βœ… Analysis Complete")
97
- st.write(response)
98
 
99
  except Exception as e:
100
  st.error(f"Error reading file: {e}")
@@ -123,21 +121,22 @@ with tab2:
123
  )
124
 
125
  if user_input:
126
- # Add user message to history
127
  st.session_state.messages.append({"role": "user", "content": user_input})
128
 
129
- # Generate AI response
130
- with st.spinner("⏳ Thinking..."):
131
- response = get_ai_response(user_input)
132
-
133
- # Add assistant message to history
134
- st.session_state.messages.append({
135
- "role": "assistant",
136
- "content": response
137
- })
138
-
139
- # Rerun to display the new messages
140
- st.rerun()
 
141
 
142
  # ============================================================================
143
  # TAB 3: About
 
12
  st.title("πŸ“Š LLM Data Analyzer")
13
  st.write("*Analyze data and chat with AI - Powered by Hugging Face Spaces*")
14
 
15
+ # Simple AI responses without API calls
16
  def get_ai_response(prompt):
17
  """Generate simple AI-like responses without external API"""
 
18
  prompt_lower = prompt.lower()
19
 
20
  # Data analysis responses
 
90
  )
91
 
92
  if question:
93
+ response = get_ai_response(question)
94
+ st.success("βœ… Analysis Complete")
95
+ st.write(response)
 
96
 
97
  except Exception as e:
98
  st.error(f"Error reading file: {e}")
 
121
  )
122
 
123
  if user_input:
124
+ # Add user message immediately
125
  st.session_state.messages.append({"role": "user", "content": user_input})
126
 
127
+ # Get response
128
+ response = get_ai_response(user_input)
129
+
130
+ # Add assistant message
131
+ st.session_state.messages.append({
132
+ "role": "assistant",
133
+ "content": response
134
+ })
135
+
136
+ # Display latest messages
137
+ st.divider()
138
+ with st.chat_message("assistant"):
139
+ st.markdown(response)
140
 
141
  # ============================================================================
142
  # TAB 3: About