Upload folder using huggingface_hub
Browse files- hate_speech_demo.py +54 -51
hate_speech_demo.py
CHANGED
|
@@ -829,56 +829,59 @@ def create_gradio_app():
|
|
| 829 |
</div>
|
| 830 |
""")
|
| 831 |
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
|
|
|
|
|
|
|
|
|
| 882 |
|
| 883 |
# Define show/hide loading indicator functions
|
| 884 |
def show_loading():
|
|
@@ -894,7 +897,7 @@ def create_gradio_app():
|
|
| 894 |
</script>"""
|
| 895 |
|
| 896 |
# Bind random test case button with loading indicator
|
| 897 |
-
|
| 898 |
show_loading,
|
| 899 |
inputs=None,
|
| 900 |
outputs=loading_spinner
|
|
|
|
| 829 |
</div>
|
| 830 |
""")
|
| 831 |
|
| 832 |
+
with gr.Row():
|
| 833 |
+
with gr.Column(scale=1):
|
| 834 |
+
# Random test case button at the top
|
| 835 |
+
random_test_btn = gr.Button("π² Random Test Case", elem_classes=["orange-button"])
|
| 836 |
+
|
| 837 |
+
# Rate Content button - moved above the input box with gray color
|
| 838 |
+
rate_btn = gr.Button("Rate Content", variant="primary", size="lg", elem_classes=["gray-button"])
|
| 839 |
+
|
| 840 |
+
# Input field below both buttons
|
| 841 |
+
user_input = gr.Textbox(label="Input content to rate:", placeholder="Type content to evaluate here...", lines=6)
|
| 842 |
+
|
| 843 |
+
with gr.Column(scale=2):
|
| 844 |
+
# Contextual Safety Oracle with policy button
|
| 845 |
+
gr.HTML("""
|
| 846 |
+
<div class="result-header" style="display: flex; align-items: center; gap: 10px;">
|
| 847 |
+
<span>π Contextual Safety Oracle</span>
|
| 848 |
+
<a href="#" class="knowledge-button" onclick="openPolicyPopup(); return false;">View policy</a>
|
| 849 |
+
</div>
|
| 850 |
+
""")
|
| 851 |
+
contextual_results = gr.HTML('<div class="rating-box contextual-box empty-rating">Rating will appear here</div>')
|
| 852 |
+
|
| 853 |
+
# Hidden placeholder for retrieved knowledge
|
| 854 |
+
retrieved_knowledge = gr.HTML('', visible=False)
|
| 855 |
+
|
| 856 |
+
with gr.Column(scale=1):
|
| 857 |
+
gr.HTML("""
|
| 858 |
+
<div class="result-header" style="display: flex; align-items: center; gap: 10px;">
|
| 859 |
+
<span>π¦ LlamaGuard 3.0</span>
|
| 860 |
+
<a href="https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard3/8B/MODEL_CARD.md"
|
| 861 |
+
target="_blank" class="knowledge-button">View model card</a>
|
| 862 |
+
</div>
|
| 863 |
+
""")
|
| 864 |
+
llama_results = gr.HTML('<div class="rating-box secondary-box empty-rating">Rating will appear here</div>')
|
| 865 |
+
|
| 866 |
+
with gr.Column(scale=1):
|
| 867 |
+
gr.HTML("""
|
| 868 |
+
<div class="result-header" style="display: flex; align-items: center; gap: 10px;">
|
| 869 |
+
<span>π§· OpenAI Moderation</span>
|
| 870 |
+
<a href="https://platform.openai.com/docs/guides/moderation"
|
| 871 |
+
target="_blank" class="knowledge-button">View model card</a>
|
| 872 |
+
</div>
|
| 873 |
+
""")
|
| 874 |
+
openai_results = gr.HTML('<div class="rating-box secondary-box empty-rating">Rating will appear here</div>')
|
| 875 |
+
|
| 876 |
+
with gr.Column(scale=1):
|
| 877 |
+
gr.HTML("""
|
| 878 |
+
<div class="result-header" style="display: flex; align-items: center; gap: 10px;">
|
| 879 |
+
<span>π§© Perspective API</span>
|
| 880 |
+
<a href="https://developers.perspectiveapi.com/s/docs"
|
| 881 |
+
target="_blank" class="knowledge-button">View docs</a>
|
| 882 |
+
</div>
|
| 883 |
+
""")
|
| 884 |
+
perspective_results = gr.HTML('<div class="rating-box secondary-box empty-rating">Rating will appear here</div>')
|
| 885 |
|
| 886 |
# Define show/hide loading indicator functions
|
| 887 |
def show_loading():
|
|
|
|
| 897 |
</script>"""
|
| 898 |
|
| 899 |
# Bind random test case button with loading indicator
|
| 900 |
+
random_test_btn.click(
|
| 901 |
show_loading,
|
| 902 |
inputs=None,
|
| 903 |
outputs=loading_spinner
|