kkata commited on
Commit
c2fefe7
·
verified ·
1 Parent(s): 7cc08a7

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -764,10 +764,17 @@ def nutrition_disorder_streamlit():
764
 
765
  # Filter input using Llama Guard
766
  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)
767
- filtered_result = filtered_result.replace("\n", " ") # Normalize the result
 
 
 
 
 
 
768
 
769
  # Check if input is safe based on allowed statuses
770
- if filtered_result in ["SAFE", "S6", "S7"]: # Blanks #3, #4, #5: Fill in with allowed safe statuses (e.g., "safe", "unsafe S7", "unsafe S6")
 
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)
 
764
 
765
  # Filter input using Llama Guard
766
  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)
767
+ if filtered_result is None:
768
+ # fail-open or fail-closed; most teams choose cautious allow for health Q&A
769
+ filtered_result = "SAFE"
770
+
771
+ label = filtered_result.replace("\n", " ").strip().upper()
772
+
773
+ #filtered_result = filtered_result.replace("\n", " ") # Normalize the result
774
 
775
  # Check if input is safe based on allowed statuses
776
+ #if filtered_result in ["SAFE", "S6", "S7"]: # Blanks #3, #4, #5: Fill in with allowed safe statuses (e.g., "safe", "unsafe S7", "unsafe S6")
777
+ if any(tag in label for tag in ("SAFE", "S6", "S7")):
778
  try:
779
  if 'chatbot' not in st.session_state:
780
  st.session_state.chatbot = NutritionBot() # Blank #6: Fill in with the chatbot class initialization (e.g., NutritionBot)