dineshsinghmehta/Cognitive_Bias_Detector
0
1import streamlit as st2 3from utils import split_into_sentences4from nli_engine import NLIBiasDetector5 6 7# -----------------------------8# Page Configuration9# -----------------------------10st.set_page_config(11 page_title="AI Cognitive Bias Detector (Intermediate)",12 layout="wide"13)14 15st.title("๐ง AI Cognitive Bias Detector")16st.markdown(17 """18 This tool analyzes text at the **sentence level** and detects 19 **cognitive biases** using a **Natural Language Inference (NLI)** model.20 21 โ ๏ธ *This is an educational tool, not a psychological diagnosis.*22 """23)24 25# -----------------------------26# Load Model (Cached)27# -----------------------------28@st.cache_resource29def load_detector():30 return NLIBiasDetector()31 32detector = load_detector()33 34# -----------------------------35# Text Input36# -----------------------------37st.subheader("๐ Enter Text")38 39input_text = st.text_area(40 label="Paste text to analyze",41 height=200,42 placeholder="Example: Everyone always lies in politics..."43)44 45# -----------------------------46# Analyze Button47# -----------------------------48if st.button("Analyze Cognitive Biases"):49 if not input_text.strip():50 st.warning("Please enter some text to analyze.")51 else:52 with st.spinner("Analyzing text for cognitive biases..."):53 sentences = split_into_sentences(input_text)54 results = detector.analyze_text(sentences)55 56 st.subheader("๐ Analysis Results")57 58 if not results:59 st.success("No strong cognitive bias detected with high confidence.")60 else:61 for idx, result in enumerate(results, start=1):62 with st.expander(f"๐ง Bias #{idx}: {result['bias']}"):63 st.markdown(f"**Sentence:** {result['sentence']}")64 st.markdown(f"**Detected Bias:** `{result['bias']}`")65 66 st.progress(result["confidence"])67 st.markdown(68 f"**Confidence Score:** `{result['confidence']}`"69 )70 