# app.py
import streamlit as st
from predictor import predict_text
# Enhanced page configuration
st.set_page_config(
page_title="AI vs Human Text Detector",
page_icon="🤖",
layout="wide",
initial_sidebar_state="collapsed"
)
# Custom CSS for stunning dark theme with black, gold, and white
st.markdown("""
""", unsafe_allow_html=True)
# Hero Section with Streamlit fallback
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
st.markdown("""
🤖 AI vs Human Detector
Unveil the origin of any text with precision. Advanced AI technology meets elegant design to deliver instant, accurate analysis of whether content was crafted by artificial intelligence or human creativity.
""", unsafe_allow_html=True)
# Emergency fallback if CSS fails on HuggingFace
if 'title_shown' not in st.session_state:
st.session_state.title_shown = True
# This will show if CSS fails
st.markdown("""
""", unsafe_allow_html=True)
# Feature Cards
st.markdown("""
⚡
Lightning Analysis
Instant results powered by state-of-the-art machine learning algorithms trained on millions of text samples.
🎯
Precision Accuracy
Advanced neural networks deliver industry-leading accuracy in distinguishing AI from human-generated content.
🔒
Privacy Assured
Your text is processed securely with zero data retention. Complete privacy and confidentiality guaranteed.
""", unsafe_allow_html=True)
# Input Section
st.markdown("""
📝 Text Analysis
""", unsafe_allow_html=True)
text_input = st.text_area(
"Text Input",
height=200,
placeholder="Paste your text here for AI detection analysis. Longer texts provide more accurate results. Whether it's an article, essay, or any written content, our advanced algorithms will analyze the linguistic patterns and provide instant results...",
help="Enter the text you want to analyze. The system works best with at least 50 words.",
key="text_input",
label_visibility="hidden"
)
# Predict Button
if st.button("🔍 Analyze Text", key="predict", type="primary"):
if text_input.strip() == "":
st.markdown("""
⚠️ Please Enter Text
Add some text in the input field above to begin the analysis.
""", unsafe_allow_html=True)
else:
# Loading animation
with st.spinner('🧠 Analyzing linguistic patterns and AI signatures...'):
prediction, confidence = predict_text(text_input)
# Display Results
if prediction == 1:
confidence_percent = confidence * 100
st.markdown(f"""
🤖 AI-Generated Content
Detection Confidence: {confidence_percent:.1f}%
This text exhibits characteristics commonly found in AI-generated content, including consistent linguistic patterns, uniform sentence structure, and computational writing markers that suggest machine generation.
""", unsafe_allow_html=True)
else:
confidence_percent = (1 - confidence) * 100
st.markdown(f"""
🧠 Human-Written Content
Detection Confidence: {confidence_percent:.1f}%
This text displays natural human writing characteristics, including varied sentence structures, personal voice, authentic linguistic nuances, and the creative inconsistencies typical of human authors.
""", unsafe_allow_html=True)
# Analysis Metrics
st.markdown("### 📊 Detailed Analysis")
col1, col2, col3 = st.columns(3)
word_count = len(text_input.split())
char_count = len(text_input)
sentences = text_input.count('.') + text_input.count('!') + text_input.count('?')
with col1:
st.markdown(f"""
{word_count}
Words Analyzed
""", unsafe_allow_html=True)
with col2:
st.markdown(f"""
{"AI" if prediction == 1 else "Human"}
Classification
""", unsafe_allow_html=True)
with col3:
complexity = len(set(text_input.lower().split())) / word_count if word_count > 0 else 0
st.markdown(f"""
{complexity:.2f}
Vocabulary Diversity
""", unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
# Footer
st.markdown("""
""", unsafe_allow_html=True)