Ankit93 commited on
Commit
1234b00
·
verified ·
1 Parent(s): 5040539

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -18,7 +18,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
18
  logging.info("Streamlit app started")
19
 
20
  # Load the API key
21
- groq_api_key = "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" #os.getenv("GROQ_API_KEY")
22
  if not groq_api_key:
23
  logging.error("GROQ API key is missing!")
24
 
@@ -115,19 +115,31 @@ st.markdown("""
115
  """, unsafe_allow_html=True)
116
 
117
  # Chat input and processing
 
 
 
118
  user_input = st.text_input("Type your message here...", key="user_input", label_visibility="collapsed")
119
 
 
120
  if user_input:
121
  condensed_question = condense_query(llm, user_input, conversation_history)
122
- response = agent_executor.invoke({"input": condensed_question})
123
 
 
 
 
 
 
 
 
 
 
124
  # Update chat history
125
  st.session_state.messages.append({"role": "user", "content": user_input})
126
- st.session_state.messages.append({"role": "assistant", "content": response.get("output", "")})
127
 
128
- # Display the response
129
  st.chat_message("user").write(user_input)
130
- st.chat_message("assistant").write(response.get("output", ""))
131
-
132
- # Clear the input field
133
- st.session_state["user_input"] = ""
 
18
  logging.info("Streamlit app started")
19
 
20
  # Load the API key
21
+ groq_api_key = os.getenv("GROQ_API_KEY")
22
  if not groq_api_key:
23
  logging.error("GROQ API key is missing!")
24
 
 
115
  """, unsafe_allow_html=True)
116
 
117
  # Chat input and processing
118
+ if "user_input" not in st.session_state:
119
+ st.session_state["user_input"] = ""
120
+
121
  user_input = st.text_input("Type your message here...", key="user_input", label_visibility="collapsed")
122
 
123
+ # If there's input, process it
124
  if user_input:
125
  condensed_question = condense_query(llm, user_input, conversation_history)
 
126
 
127
+ # Placeholder for streaming the assistant's response
128
+ response_placeholder = st.empty()
129
+ response_text = ""
130
+
131
+ # Stream response tokens
132
+ for token in agent_executor.stream({"input": condensed_question}):
133
+ response_text += token["output"]
134
+ response_placeholder.write(response_text)
135
+
136
  # Update chat history
137
  st.session_state.messages.append({"role": "user", "content": user_input})
138
+ st.session_state.messages.append({"role": "assistant", "content": response_text})
139
 
140
+ # Display the user input and response
141
  st.chat_message("user").write(user_input)
142
+ st.chat_message("assistant").write(response_text)
143
+
144
+ # Reset the user input by updating session_state
145
+ st.session_state.user_input = ""