File size: 938 Bytes
2da86c3
132e9a7
 
2da86c3
 
b20c6fa
132e9a7
c3e5b17
2da86c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16888d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import os
api_key = os.getenv("SECRET_TOKEN")

# Load the model from Hugging Face
model_name = "comment-toxicity-analyzer/toxicity_det"

interface = gr.load(model_name, src="spaces", hf_api_key=api_key)

def score_comment(comment):
    """
    This function will take in a comment and then pass it through a prediction pipeline.
    """
    # Make predictions using the Gradio interface
    results = interface.predict([comment])

    # Process the results
    text = ""
    for idx, col in enumerate(["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]):
        text += f"{col}: {results[0][col] > 0.40}\n"

    return text

# Define the Gradio interface
interface = gr.Interface(
    fn=score_comment,
    inputs=gr.inputs.Textbox(lines=2, placeholder="Comment to score"),
    outputs="text"
)

# Launch the interface on a local server
# if __name__ == "__main__":
interface.launch(share=True)