File size: 919 Bytes
c3ccf82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
from transformers import pipeline

# Load FLAN-T5 pipeline
classifier = pipeline("text2text-generation", model="google/flan-t5-base", max_length=32)

# Prompt template
def classify_bias(headline):
    prompt = f"Classify the political bias of this headline as Left, Center, or Right: '{headline}'"
    output = classifier(prompt)[0]['generated_text'].strip()
    return output

# Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("# 🧠 BiasLens – Political Bias Detector")
    gr.Markdown("Enter a news headline to detect whether it's Left, Center, or Right biased.")

    headline_input = gr.Textbox(label="📰 Enter News Headline", placeholder="e.g. Biden signs climate bill")
    result_output = gr.Textbox(label="🧭 Predicted Bias")

    classify_btn = gr.Button("Classify Bias")

    classify_btn.click(fn=classify_bias, inputs=[headline_input], outputs=[result_output])

demo.launch()