biasdetect / app.py
himel7's picture
Create app.py
6da6acb verified
raw
history blame
1.48 kB
import gradio as gr
from transformers import pipeline
# Load both models
bias_detector = pipeline("text-classification", model="himel7/bias-detector")
bias_type_classifier = pipeline("text-classification", model="maximuspowers/bias-type-classifier")
def detect_bias_and_type(text):
detection_result = bias_detector(text)[0]
label = detection_result['label']
score = detection_result['score']
if label == "LABEL_1": # Biased
type_result = bias_type_classifier(text)[0]
bias_type = type_result['label']
type_score = type_result['score']
return (f"🧐 **Bias Detected!**\n"
f"- **Bias Probability:** {score:.2%}\n"
f"- **Bias Type:** {bias_type} (Confidence: {type_score:.2%})")
else:
return f"βœ… **Unbiased** (Confidence: {score:.2%})"
# Gradio UI
iface = gr.Interface(
fn=detect_bias_and_type,
inputs=gr.Textbox(lines=3, placeholder="Enter a sentence..."),
outputs="markdown",
title="Bias Detector + Bias Type Classifier",
description=(
"This tool detects whether a text is biased and classifies the type of bias.\n"
"Models: `himel7/bias-detector` and `maximuspowers/bias-type-classifier`"
),
examples=[
["The brilliant leader saved the country from disaster."],
["The government announced new tax reforms."],
["The selfish billionaire hoarded his wealth."]
]
)
if __name__ == "__main__":
iface.launch()