Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load FLAN-T5 pipeline
|
| 5 |
+
classifier = pipeline("text2text-generation", model="google/flan-t5-base", max_length=32)
|
| 6 |
+
|
| 7 |
+
# Prompt template
|
| 8 |
+
def classify_bias(headline):
|
| 9 |
+
prompt = f"Classify the political bias of this headline as Left, Center, or Right: '{headline}'"
|
| 10 |
+
output = classifier(prompt)[0]['generated_text'].strip()
|
| 11 |
+
return output
|
| 12 |
+
|
| 13 |
+
# Gradio UI
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("# 🧠 BiasLens – Political Bias Detector")
|
| 16 |
+
gr.Markdown("Enter a news headline to detect whether it's Left, Center, or Right biased.")
|
| 17 |
+
|
| 18 |
+
headline_input = gr.Textbox(label="📰 Enter News Headline", placeholder="e.g. Biden signs climate bill")
|
| 19 |
+
result_output = gr.Textbox(label="🧭 Predicted Bias")
|
| 20 |
+
|
| 21 |
+
classify_btn = gr.Button("Classify Bias")
|
| 22 |
+
|
| 23 |
+
classify_btn.click(fn=classify_bias, inputs=[headline_input], outputs=[result_output])
|
| 24 |
+
|
| 25 |
+
demo.launch()
|