Upload folder using huggingface_hub
Browse files- hate_speech_demo.py +14 -79
hate_speech_demo.py
CHANGED
|
@@ -622,91 +622,26 @@ def create_gradio_app():
|
|
| 622 |
border_color_primary="#E0E0E0"
|
| 623 |
)
|
| 624 |
|
| 625 |
-
# Then use the defined theme in gr.Blocks
|
| 626 |
with gr.Blocks(title="Hate Speech Rating Oracle", theme=theme, css=CUSTOM_CSS) as app:
|
| 627 |
-
#
|
| 628 |
loading_spinner = gr.HTML('<div id="loading-spinner"></div>')
|
| 629 |
|
| 630 |
-
#
|
| 631 |
-
pdf_file = gr.File("Hate Speech Policy.pdf", visible=False, label="Policy PDF")
|
| 632 |
|
| 633 |
-
#
|
| 634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
|
| 636 |
-
|
| 637 |
-
|
|
|
|
|
|
|
|
|
|
| 638 |
|
| 639 |
-
#
|
| 640 |
-
with gr.Row():
|
| 641 |
-
with gr.Column(scale=1):
|
| 642 |
-
# Random test case button at the top
|
| 643 |
-
random_test_btn = gr.Button("🎲 Random Test Case", elem_classes=["orange-button"])
|
| 644 |
-
|
| 645 |
-
# Rate Content button
|
| 646 |
-
rate_btn = gr.Button("Rate Content", variant="primary", size="lg", elem_classes=["gray-button"])
|
| 647 |
-
|
| 648 |
-
# Input field below both buttons
|
| 649 |
-
user_input = gr.Textbox(label="Input content to rate:", placeholder="Type content to evaluate here...", lines=6)
|
| 650 |
-
|
| 651 |
-
# Define output elements
|
| 652 |
-
with gr.Row():
|
| 653 |
-
with gr.Column(scale=1, elem_classes=["model-column"]):
|
| 654 |
-
# Contextual AI section
|
| 655 |
-
gr.HTML("""
|
| 656 |
-
<div>
|
| 657 |
-
<h3 class="result-header">🌟 Contextual Safety Oracle</h3>
|
| 658 |
-
<div style="margin-top: -10px; margin-bottom: 10px;">
|
| 659 |
-
<a href="#" class="knowledge-button" onclick="openPolicyPopup(); return false;">View policy</a>
|
| 660 |
-
</div>
|
| 661 |
-
</div>
|
| 662 |
-
""")
|
| 663 |
-
contextual_results = gr.HTML('<div class="rating-box contextual-box empty-rating">Rating will appear here</div>')
|
| 664 |
-
|
| 665 |
-
with gr.Row():
|
| 666 |
-
with gr.Column(scale=1, elem_classes=["model-column"]):
|
| 667 |
-
# LlamaGuard section
|
| 668 |
-
gr.HTML("""
|
| 669 |
-
<div>
|
| 670 |
-
<h3 class="result-header">🦙 LlamaGuard 3.0</h3>
|
| 671 |
-
<div style="margin-top: -10px; margin-bottom: 10px;">
|
| 672 |
-
<a href="https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard3/8B/MODEL_CARD.md"
|
| 673 |
-
target="_blank" class="knowledge-button">View model card</a>
|
| 674 |
-
</div>
|
| 675 |
-
</div>
|
| 676 |
-
""")
|
| 677 |
-
llama_results = gr.HTML('<div class="rating-box secondary-box empty-rating">Rating will appear here</div>')
|
| 678 |
-
with gr.Column(scale=1, elem_classes=["model-column"]):
|
| 679 |
-
# OpenAI section
|
| 680 |
-
gr.HTML("""
|
| 681 |
-
<div>
|
| 682 |
-
<h3 class="result-header">🧷 OpenAI Moderation</h3>
|
| 683 |
-
<div style="margin-top: -10px; margin-bottom: 10px;">
|
| 684 |
-
<a href="https://platform.openai.com/docs/guides/moderation"
|
| 685 |
-
target="_blank" class="knowledge-button">View model card</a>
|
| 686 |
-
</div>
|
| 687 |
-
</div>
|
| 688 |
-
""")
|
| 689 |
-
openai_results = gr.HTML('<div class="rating-box secondary-box empty-rating">Rating will appear here</div>')
|
| 690 |
-
with gr.Column(scale=1, elem_classes=["model-column"]):
|
| 691 |
-
# Perspective API section
|
| 692 |
-
gr.HTML("""
|
| 693 |
-
<div>
|
| 694 |
-
<h3 class="result-header">👁️ Perspective API</h3>
|
| 695 |
-
<div style="margin-top: -10px; margin-bottom: 10px;">
|
| 696 |
-
<a href="https://developers.perspectiveapi.com/s/about-the-api"
|
| 697 |
-
target="_blank" class="knowledge-button">View model card</a>
|
| 698 |
-
</div>
|
| 699 |
-
</div>
|
| 700 |
-
""")
|
| 701 |
-
perspective_results = gr.HTML('<div class="rating-box secondary-box empty-rating">Rating will appear here</div>')
|
| 702 |
-
|
| 703 |
-
# Hidden element for retrieved knowledge
|
| 704 |
-
retrieved_knowledge = gr.HTML('', visible=False)
|
| 705 |
-
|
| 706 |
-
# After defining all UI elements, set up the event handlers
|
| 707 |
-
# Define show/hide loading functions first...
|
| 708 |
-
|
| 709 |
-
# Bind the buttons
|
| 710 |
random_test_btn.click(
|
| 711 |
show_loading,
|
| 712 |
inputs=None,
|
|
|
|
| 622 |
border_color_primary="#E0E0E0"
|
| 623 |
)
|
| 624 |
|
|
|
|
| 625 |
with gr.Blocks(title="Hate Speech Rating Oracle", theme=theme, css=CUSTOM_CSS) as app:
|
| 626 |
+
# Add loading spinner
|
| 627 |
loading_spinner = gr.HTML('<div id="loading-spinner"></div>')
|
| 628 |
|
| 629 |
+
# Rest of your UI definition code...
|
|
|
|
| 630 |
|
| 631 |
+
# Define show/hide loading indicator functions BEFORE using them
|
| 632 |
+
def show_loading():
|
| 633 |
+
return """<script>
|
| 634 |
+
const spinner = document.getElementById('loading-spinner');
|
| 635 |
+
if (spinner) spinner.style.display = 'block';
|
| 636 |
+
</script>"""
|
| 637 |
|
| 638 |
+
def hide_loading():
|
| 639 |
+
return """<script>
|
| 640 |
+
const spinner = document.getElementById('loading-spinner');
|
| 641 |
+
if (spinner) spinner.style.display = 'none';
|
| 642 |
+
</script>"""
|
| 643 |
|
| 644 |
+
# Then bind the buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
random_test_btn.click(
|
| 646 |
show_loading,
|
| 647 |
inputs=None,
|