File size: 5,830 Bytes
469c254
 
 
 
16c79b6
469c254
f4eed50
 
84ba156
 
a45e52d
 
f4eed50
 
a45e52d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ba156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a45e52d
 
 
469c254
a45e52d
16c79b6
469c254
16c79b6
 
 
 
 
 
 
 
a45e52d
16c79b6
a45e52d
 
16c79b6
 
469c254
 
 
 
 
84ba156
 
 
 
 
 
 
 
 
 
 
 
 
a45e52d
84ba156
 
a45e52d
 
84ba156
 
 
 
 
 
 
 
 
a45e52d
 
84ba156
 
a45e52d
84ba156
 
 
 
 
 
a45e52d
 
84ba156
 
 
 
 
 
 
 
 
 
 
 
469c254
84ba156
a45e52d
 
 
 
 
84ba156
a45e52d
 
84ba156
a45e52d
16c79b6
84ba156
a45e52d
84ba156
 
 
a45e52d
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import sys
from pathlib import Path
import os
import gdown
import streamlit as st

# Set page config - must be first Streamlit command
st.set_page_config(
    page_title="TruthCheck - Advanced Fake News Detector",
    page_icon="πŸ›‘οΈ",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS for modern styling
st.markdown("""
<style>
    @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
    
    body {
        font-family: 'Poppins', sans-serif;
        background-color: #FFFFFF;
        color: #333333;
    }
    
    .sidebar .sidebar-content {
        background-color: #F4F7FA;
        padding: 1rem;
    }
    
    .stButton>button {
        background-color: #4B5EAA;
        color: white;
        border-radius: 8px;
        padding: 0.5rem 1rem;
        font-weight: 600;
        transition: background-color 0.3s;
    }
    
    .stButton>button:hover {
        background-color: #3A4A8C;
    }
    
    .stTextArea textarea {
        border: 1px solid #E0E0E0;
        border-radius: 8px;
        padding: 1rem;
    }
    
    .hero-section {
        background-color: #F4F7FA;
        padding: 2rem;
        border-radius: 12px;
        margin-bottom: 2rem;
    }
    
    .flash-message {
        padding: 1rem;
        border-radius: 8px;
        margin-bottom: 1rem;
        font-weight: 600;
    }
    
    .success-message {
        background-color: #E6F4EA;
        color: #2E7D32;
    }
    
    .error-message {
        background-color: #FEE2E2;
        color: #B71C1C;
    }
    
    /* Enhanced sidebar styling */
    .stRadio > div {
        gap: 0.5rem;
    }
    
    .stRadio > div > label {
        padding: 0.5rem 1rem;
        border-radius: 8px;
        transition: all 0.3s ease;
        cursor: pointer;
        font-weight: 500;
    }
    
    .stRadio > div > label:hover {
        background-color: #E8F0FE;
        transform: translateX(5px);
    }
    
    .stRadio > div > label[data-checked="true"] {
        background-color: #4B5EAA;
        color: white;
    }
</style>
""", unsafe_allow_html=True)

MODEL_PATH = "models/saved/final_model.pt"
GOOGLE_DRIVE_FILE_ID = "1xhYKuC5_Yri3mm3Ejt-SpB2WAVUTJvc_"
GOOGLE_DRIVE_URL = f"https://drive.google.com/uc?id={GOOGLE_DRIVE_FILE_ID}"

@st.cache_resource
def download_model():
    """Download model from Google Drive if not exists."""
    if not os.path.exists(MODEL_PATH):
        os.makedirs(os.path.dirname(MODEL_PATH), exist_ok=True)
        with st.spinner("Downloading model from Google Drive..."):
            try:
                gdown.download(GOOGLE_DRIVE_URL, MODEL_PATH, quiet=False)
                st.markdown('<div class="flash-message success-message">Model downloaded successfully!</div>', unsafe_allow_html=True)
            except Exception as e:
                st.markdown(f'<div class="flash-message error-message">Failed to download model: {str(e)}</div>', unsafe_allow_html=True)
                st.markdown('<div class="flash-message error-message">Please check your Google Drive link and make sure the file is publicly accessible.</div>', unsafe_allow_html=True)
                return False
    return True

# Add src directory to Python path
src_path = Path(__file__).parent / "src"
sys.path.append(str(src_path))

# Enhanced Sidebar navigation with icons
st.sidebar.markdown("""
<div style="text-align: center; margin-bottom: 2rem;">
    <div style="font-size: 2.5rem; margin-bottom: 0.5rem;">πŸ›‘οΈ</div>
    <h1 style="color: #4B5EAA; font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; line-height: 1.2;">
        TruthCheck
    </h1>
    <p style="color: #666; font-size: 0.9rem; margin: 0; font-weight: 300; line-height: 1.3;">
        Advanced Fake News Detector
    </p>
</div>
""", unsafe_allow_html=True)

st.sidebar.markdown("---")

# Navigation with icons
page = st.sidebar.radio(
    "Navigate",
    [
        "🏠 Home",
        "ℹ️ About", 
        "πŸ“‹ Terms of Use",
        "πŸ”’ Privacy Policy",
        "πŸ‘₯ Team"
    ],
    label_visibility="collapsed",
    key="navigation"
)

# Add some spacing and additional info
st.sidebar.markdown("---")
st.sidebar.markdown("""
<div style="text-align: center; padding: 1.5rem; background: linear-gradient(135deg, #F8F9FA 0%, #E8F0FE 100%); border-radius: 12px; margin-top: 1rem; border: 1px solid #E0E7FF;">
    <div style="font-size: 2rem; margin-bottom: 0.8rem;">πŸ”</div>
    <p style="font-size: 0.85rem; color: #4B5EAA; margin: 0; font-weight: 500; line-height: 1.4;">
        Protecting you from misinformation with AI-powered detection
    </p>
</div>
""", unsafe_allow_html=True)

# Add footer info
st.sidebar.markdown("""
<div style="position: fixed; bottom: 1rem; left: 1rem; right: 1rem; text-align: center; padding: 0.5rem; background-color: rgba(255,255,255,0.9); border-radius: 8px; border-top: 1px solid #E0E0E0;">
    <p style="font-size: 0.7rem; color: #888; margin: 0;">
        Β© 2025 TruthCheck | AI-Powered
    </p>
</div>
""", unsafe_allow_html=True)

# Clean up the page variable to remove icons for the conditional logic
page_clean = page.split(" ", 1)[1] if " " in page else page

if __name__ == "__main__":
    if page_clean == "Home":
        if download_model():
            from src.app import main
            main()
        else:
            st.markdown('<div class="flash-message error-message">Cannot start the application without the model file.</div>', unsafe_allow_html=True)
    elif page_clean == "About":
        from src.about import main
        main()
    elif page_clean == "Terms of Use":
        from src.terms_of_use import main
        main()
    elif page_clean == "Privacy Policy":
        from src.privacy_policy import main
        main()
    elif page_clean == "Team":
        from src.team import main
        main()