bias.bin / app.py
aryn25's picture
Update app.py
add7ad3 verified
raw
history blame
1.25 kB
import gradio as gr
from transformers import pipeline
# Load the zero-shot classifier for bias detection using Facebook's BART MNLI.
classifier = pipeline(
"zero-shot-classification",
model="facebook/bart-large-mnli"
)
def process_text(text):
# Define candidate labels for bias classification.
candidate_labels = ["biased", "neutral"]
# Run zero-shot classification.
classification = classifier(text, candidate_labels)
detected_bias = classification["labels"][0]
confidence = classification["scores"][0]
# Return the results.
return {
"Detected Bias": detected_bias,
"Confidence": round(confidence, 2),
}
# Build the Gradio UI.
with gr.Blocks() as demo:
gr.Markdown("# Bias Bin")
gr.Markdown(
"Detect gender stereotypes in narrative text. "
"Enter a story or sentence below and click the **Submit** button."
)
text_input = gr.Textbox(
label="Enter Story Text",
placeholder="Type a story or sentence here...",
lines=5
)
submit_btn = gr.Button("Submit")
result_output = gr.JSON(label="Output")
submit_btn.click(fn=process_text, inputs=[text_input], outputs=[result_output])
demo.launch()