|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
classifier = pipeline( |
|
|
"zero-shot-classification", |
|
|
model="facebook/bart-large-mnli" |
|
|
) |
|
|
|
|
|
def process_text(text): |
|
|
|
|
|
candidate_labels = ["biased", "neutral"] |
|
|
|
|
|
|
|
|
classification = classifier(text, candidate_labels) |
|
|
detected_bias = classification["labels"][0] |
|
|
confidence = classification["scores"][0] |
|
|
|
|
|
|
|
|
return { |
|
|
"Detected Bias": detected_bias, |
|
|
"Confidence": round(confidence, 2), |
|
|
} |
|
|
|
|
|
|
|
|
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() |