Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -677,7 +677,7 @@ class NutritionBot:
|
|
677 |
context += "---\n"
|
678 |
|
679 |
# Print context for debugging purposes
|
680 |
-
|
681 |
|
682 |
# Prepare a prompt combining past context and the current query
|
683 |
prompt = f"""
|
@@ -691,7 +691,7 @@ class NutritionBot:
|
|
691 |
#st.write("Context: ", prompt)
|
692 |
|
693 |
# Generate a response using the agent
|
694 |
-
response = self.agent_executor.invoke({"input": prompt
|
695 |
st.write("Context: ", response)
|
696 |
|
697 |
# Store the current interaction for future reference
|
@@ -763,7 +763,13 @@ def nutrition_disorder_streamlit():
|
|
763 |
|
764 |
# Filter input using Llama Guard
|
765 |
filtered_result = filter_input_with_llama_guard(user_query) # Blank #2: Fill in with the function name for filtering input (e.g., filter_input_with_llama_guard)
|
766 |
-
filtered_result = filtered_result.replace("\n", " ") # Normalize the result
|
|
|
|
|
|
|
|
|
|
|
|
|
767 |
|
768 |
# Check if input is safe based on allowed statuses
|
769 |
if filtered_result in ["safe", "safe S7", "safe S6"]: # Blanks #3, #4, #5: Fill in with allowed safe statuses (e.g., "safe", "unsafe S7", "unsafe S6")
|
@@ -771,11 +777,13 @@ def nutrition_disorder_streamlit():
|
|
771 |
try:
|
772 |
if 'chatbot' not in st.session_state:
|
773 |
st.session_state.chatbot = NutritionBot() # Blank #6: Fill in with the chatbot class initialization (e.g., NutritionBot)
|
774 |
-
#st.write("chatbot
|
775 |
-
|
|
|
776 |
response = st.session_state.chatbot.handle_customer_query(st.session_state.user_id, user_query)
|
777 |
#st.write("response is returned.")
|
778 |
# Blank #7: Fill in with the method to handle queries (e.g., handle_customer_query)
|
|
|
779 |
st.write(response)
|
780 |
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
781 |
except Exception as e:
|
|
|
677 |
context += "---\n"
|
678 |
|
679 |
# Print context for debugging purposes
|
680 |
+
print("Context: ", context)
|
681 |
|
682 |
# Prepare a prompt combining past context and the current query
|
683 |
prompt = f"""
|
|
|
691 |
#st.write("Context: ", prompt)
|
692 |
|
693 |
# Generate a response using the agent
|
694 |
+
response = self.agent_executor.invoke({"input": prompt})
|
695 |
st.write("Context: ", response)
|
696 |
|
697 |
# Store the current interaction for future reference
|
|
|
763 |
|
764 |
# Filter input using Llama Guard
|
765 |
filtered_result = filter_input_with_llama_guard(user_query) # Blank #2: Fill in with the function name for filtering input (e.g., filter_input_with_llama_guard)
|
766 |
+
#filtered_result = filtered_result.replace("\n", " ") # Normalize the result
|
767 |
+
if filtered_result is None:
|
768 |
+
print("Agent: Sorry, I encountered an error while filtering your input. Please try again.")
|
769 |
+
continue
|
770 |
+
else:
|
771 |
+
filtered_result = filtered_result.replace("\n", " ") # Normalize the result
|
772 |
+
print(f"filtered_result (2): {filtered_result}")
|
773 |
|
774 |
# Check if input is safe based on allowed statuses
|
775 |
if filtered_result in ["safe", "safe S7", "safe S6"]: # Blanks #3, #4, #5: Fill in with allowed safe statuses (e.g., "safe", "unsafe S7", "unsafe S6")
|
|
|
777 |
try:
|
778 |
if 'chatbot' not in st.session_state:
|
779 |
st.session_state.chatbot = NutritionBot() # Blank #6: Fill in with the chatbot class initialization (e.g., NutritionBot)
|
780 |
+
#st.write("chatbot is calling handle_customer_query...")
|
781 |
+
#st.write("user_id: ", st.session_state.user_id)
|
782 |
+
#st.write("user_query: ", user_query)
|
783 |
response = st.session_state.chatbot.handle_customer_query(st.session_state.user_id, user_query)
|
784 |
#st.write("response is returned.")
|
785 |
# Blank #7: Fill in with the method to handle queries (e.g., handle_customer_query)
|
786 |
+
|
787 |
st.write(response)
|
788 |
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
789 |
except Exception as e:
|