TruthCheck / app.py
adnaan05's picture
Update app.py (#1)
a45e52d verified
raw
history blame
5.89 kB
# 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="TrueCheck - Fake News Detection",
# page_icon="📰",
# layout="wide"
# )
# MODEL_PATH = "models/saved/final_model.pt"
# # You need to replace this with the direct download link of your model file
# # To get the direct link: Right-click your model file in Google Drive -> Get link -> Make sure it's set to "Anyone with the link can view"
# # Then replace the file ID in the URL below
# GOOGLE_DRIVE_FILE_ID = "1xhYKuC5_Yri3mm3Ejt-SpB2WAVUTJvc_" # Replace with your actual file ID
# 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.success("Model downloaded successfully!")
# except Exception as e:
# st.error(f"Failed to download model: {str(e)}")
# st.error("Please check your Google Drive link and make sure the file is publicly accessible.")
# return False
# return True
# # Add src directory to Python path
# src_path = Path(__file__).parent / "src"
# sys.path.append(str(src_path))
# if __name__ == "__main__":
# # Download model first
# if download_model():
# # Import and run the main app
# from src.app import main
# main()
# else:
# st.error("Cannot start the application without the model file.")
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="TrueCheck - Fake News Detection",
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;
}
</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))
# Sidebar navigation
st.sidebar.title("TrueCheck")
st.sidebar.markdown("---")
page = st.sidebar.radio(
"Navigate",
["Home", "Team", "About", "Terms of Use", "Privacy Policy"],
label_visibility="collapsed"
)
# SVG icon for sidebar
st.sidebar.markdown("""
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#4B5EAA" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="margin-bottom: 1rem;">
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
<polyline points="9 22 9 12 15 12 15 22"></polyline>
</svg>
""", unsafe_allow_html=True)
if __name__ == "__main__":
if page == "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 == "Team":
from src.team import main
main()
elif page == "About":
from src.about import main
main()
elif page == "Terms of Use":
from src.terms_of_use import main
main()
elif page == "Privacy Policy":
from src.privacy_policy import main
main()