|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
classifier = pipeline("text2text-generation", model="google/flan-t5-base", max_length=32) |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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() |