Upload folder using huggingface_hub
Browse files- hate_speech_demo.py +10 -10
hate_speech_demo.py
CHANGED
|
@@ -444,16 +444,16 @@ def get_openai_moderation(openai_client, user_input):
|
|
| 444 |
|
| 445 |
|
| 446 |
# Updated to only require one input
|
| 447 |
-
def rate_user_input(user_input
|
| 448 |
# Initialize APIs with hardcoded keys
|
| 449 |
contextual_api = ContextualAPIUtils(api_key=ORACLE_API_KEY)
|
| 450 |
together_client = Together(api_key=TOGETHER_API_KEY)
|
| 451 |
openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
|
| 452 |
|
| 453 |
-
# Get ratings
|
| 454 |
-
llama_rating, llama_safety = get_llama_guard_rating(together_client, user_input
|
| 455 |
-
contextual_rating, contextual_retrieval, contextual_safety = get_contextual_rating(contextual_api, user_input
|
| 456 |
-
openai_rating, openai_safety = get_openai_moderation(openai_client, user_input
|
| 457 |
|
| 458 |
# Format responses carefully to avoid random line breaks
|
| 459 |
llama_rating = re.sub(r'\.(?=\s+[A-Z])', '.\n', llama_rating)
|
|
@@ -491,17 +491,17 @@ def rate_user_input(user_input, user_response):
|
|
| 491 |
</div>
|
| 492 |
"""
|
| 493 |
|
| 494 |
-
# Create a toggle button
|
| 495 |
knowledge_button = f"""
|
| 496 |
<div style="margin-top: 10px; margin-bottom: 5px;">
|
| 497 |
-
<
|
| 498 |
onclick="document.getElementById('{popup_id}').style.display='block'; this.style.display='none'; return false;">
|
| 499 |
-
Show
|
| 500 |
-
</
|
| 501 |
</div>
|
| 502 |
"""
|
| 503 |
|
| 504 |
-
# Format contextual results with HTML styling -
|
| 505 |
contextual_html = f"""
|
| 506 |
<div class="rating-box contextual-box {contextual_safety}-rating">
|
| 507 |
<button class="copy-button" onclick="navigator.clipboard.writeText(this.parentElement.innerText.replace('Copy', ''))">Copy</button>
|
|
|
|
| 444 |
|
| 445 |
|
| 446 |
# Updated to only require one input
|
| 447 |
+
def rate_user_input(user_input):
|
| 448 |
# Initialize APIs with hardcoded keys
|
| 449 |
contextual_api = ContextualAPIUtils(api_key=ORACLE_API_KEY)
|
| 450 |
together_client = Together(api_key=TOGETHER_API_KEY)
|
| 451 |
openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
|
| 452 |
|
| 453 |
+
# Get ratings (now only using user_input)
|
| 454 |
+
llama_rating, llama_safety = get_llama_guard_rating(together_client, user_input)
|
| 455 |
+
contextual_rating, contextual_retrieval, contextual_safety = get_contextual_rating(contextual_api, user_input)
|
| 456 |
+
openai_rating, openai_safety = get_openai_moderation(openai_client, user_input)
|
| 457 |
|
| 458 |
# Format responses carefully to avoid random line breaks
|
| 459 |
llama_rating = re.sub(r'\.(?=\s+[A-Z])', '.\n', llama_rating)
|
|
|
|
| 491 |
</div>
|
| 492 |
"""
|
| 493 |
|
| 494 |
+
# Create a toggle button (positioned BELOW the contextual results)
|
| 495 |
knowledge_button = f"""
|
| 496 |
<div style="margin-top: 10px; margin-bottom: 5px;">
|
| 497 |
+
<a href="#" id="btn-{popup_id}" class="knowledge-button"
|
| 498 |
onclick="document.getElementById('{popup_id}').style.display='block'; this.style.display='none'; return false;">
|
| 499 |
+
Show supporting evidence
|
| 500 |
+
</a>
|
| 501 |
</div>
|
| 502 |
"""
|
| 503 |
|
| 504 |
+
# Format contextual results with HTML styling - button comes AFTER the results
|
| 505 |
contextual_html = f"""
|
| 506 |
<div class="rating-box contextual-box {contextual_safety}-rating">
|
| 507 |
<button class="copy-button" onclick="navigator.clipboard.writeText(this.parentElement.innerText.replace('Copy', ''))">Copy</button>
|