rwillats commited on
Commit
80fa2b5
·
verified ·
1 Parent(s): d933a87

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. hate_speech_demo.py +14 -4
hate_speech_demo.py CHANGED
@@ -513,15 +513,25 @@ def get_contextual_rating(contextual_api, user_input):
513
  if error:
514
  return f"Error: {error}", "", "unsafe"
515
 
 
 
 
516
  # Determine safety level based on response content
517
  safety_level = "safe"
518
- if "out of policy" in response_text.lower() or "unsafe" in response_text.lower():
519
  safety_level = "unsafe"
520
- elif "caution" in response_text.lower() or "warning" in response_text.lower():
521
  safety_level = "warning"
522
 
523
- # Format the response text to separate rating, category, and explanation
524
- formatted_response = format_contextual_rating(response_text)
 
 
 
 
 
 
 
525
 
526
  return formatted_response, retrieval_text, safety_level
527
 
 
513
  if error:
514
  return f"Error: {error}", "", "unsafe"
515
 
516
+ # Store the original response for safety level detection
517
+ original_response = response_text
518
+
519
  # Determine safety level based on response content
520
  safety_level = "safe"
521
+ if "out of policy" in original_response.lower() or "unsafe" in original_response.lower():
522
  safety_level = "unsafe"
523
+ elif "caution" in original_response.lower() or "warning" in original_response.lower():
524
  safety_level = "warning"
525
 
526
+ # Try to format the response (but keep the original if anything goes wrong)
527
+ try:
528
+ # Simple formatting approach - just add line breaks between sentences
529
+ formatted_response = response_text.replace(". ", ".<br><br>")
530
+ # Ensure we don't have too many breaks
531
+ formatted_response = formatted_response.replace("<br><br><br>", "<br><br>")
532
+ except Exception as e:
533
+ print(f"Error formatting response: {e}")
534
+ formatted_response = response_text
535
 
536
  return formatted_response, retrieval_text, safety_level
537