sagacious-satadru's picture
Update app.py
132e9a7
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)