Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
bias_detector = pipeline("text-classification", model="himel7/bias-detector")
|
| 6 |
bias_type_classifier = pipeline("text-classification", model="maximuspowers/bias-type-classifier")
|
| 7 |
|
|
@@ -12,11 +12,7 @@ def detect_bias_and_type(text):
|
|
| 12 |
|
| 13 |
if label == "LABEL_1": # Biased
|
| 14 |
type_result = bias_type_classifier(text)[0]
|
| 15 |
-
|
| 16 |
-
type_score = type_result['score']
|
| 17 |
-
return (f"🧐 **Bias Detected!**\n"
|
| 18 |
-
f"- **Bias Probability:** {score:.2%}\n"
|
| 19 |
-
f"- **Bias Type:** {bias_type} (Confidence: {type_score:.2%})")
|
| 20 |
else:
|
| 21 |
return f"✅ **Unbiased** (Confidence: {score:.2%})"
|
| 22 |
|
|
@@ -37,20 +33,28 @@ badges_html = """
|
|
| 37 |
</p>
|
| 38 |
"""
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load models
|
| 5 |
bias_detector = pipeline("text-classification", model="himel7/bias-detector")
|
| 6 |
bias_type_classifier = pipeline("text-classification", model="maximuspowers/bias-type-classifier")
|
| 7 |
|
|
|
|
| 12 |
|
| 13 |
if label == "LABEL_1": # Biased
|
| 14 |
type_result = bias_type_classifier(text)[0]
|
| 15 |
+
return f"🧐 **Bias Detected!**\n- Bias Probability: {score:.2%}\n- Bias Type: {type_result['label']} ({type_result['score']:.2%})"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
else:
|
| 17 |
return f"✅ **Unbiased** (Confidence: {score:.2%})"
|
| 18 |
|
|
|
|
| 33 |
</p>
|
| 34 |
"""
|
| 35 |
|
| 36 |
+
with gr.Blocks() as demo:
|
| 37 |
+
# Render badges using HTML (not escaped)
|
| 38 |
+
gr.HTML(badges_html)
|
| 39 |
+
|
| 40 |
+
gr.Markdown("## Bias Analyzer")
|
| 41 |
+
gr.Markdown("Enter a sentence to detect bias and its type.")
|
| 42 |
+
|
| 43 |
+
text_input = gr.Textbox(lines=3, placeholder="Enter a sentence...")
|
| 44 |
+
output = gr.Markdown()
|
| 45 |
+
|
| 46 |
+
btn = gr.Button("Analyze")
|
| 47 |
+
btn.click(detect_bias_and_type, inputs=text_input, outputs=output)
|
| 48 |
+
|
| 49 |
+
# Examples
|
| 50 |
+
gr.Examples(
|
| 51 |
+
examples=[
|
| 52 |
+
["The brilliant leader saved the country from disaster."],
|
| 53 |
+
["The government announced new tax reforms."],
|
| 54 |
+
["The selfish billionaire hoarded his wealth."]
|
| 55 |
+
],
|
| 56 |
+
inputs=text_input
|
| 57 |
+
)
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|