himel7 commited on
Commit
86d3754
·
verified ·
1 Parent(s): 3b9f749

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load both 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,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
- bias_type = type_result['label']
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
- # Gradio UI
41
- iface = gr.Interface(
42
- fn=detect_bias_and_type,
43
- inputs=gr.Textbox(lines=3, placeholder="Enter a sentence..."),
44
- outputs="markdown",
45
- title="Bias Analyser",
46
- description=badges_html,
47
- #("This tool detects whether a text is biased and classifies the type of bias.\n"),
48
- examples=[
49
- ["The brilliant leader saved the country from disaster."],
50
- ["The government announced new tax reforms."],
51
- ["The selfish billionaire hoarded his wealth."]
52
- ]
53
- )
 
 
 
 
 
 
 
 
54
 
55
  if __name__ == "__main__":
56
- iface.launch()
 
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()