import streamlit as st import torch from transformers import AutoTokenizer, AutoModelForSequenceClassification import pandas as pd # --- Page Configuration --- st.set_page_config( page_title="SENTINEL AI", page_icon="🤖", layout="wide" ) # --- Caching the Model --- @st.cache_resource def load_model(): print("🚀 Loading the fine-tuned RoBERTa model...") MODEL_PATH = "Shifterr/sentiment_model_roberta" # !! Make sure this matches your folder name !! tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH) model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH) print("✅ Model loaded successfully!") return tokenizer, model # Load the model and tokenizer tokenizer, model = load_model() labels = ['Negative emotion', 'Neutral', 'Positive emotion'] # --- Prediction Function (Upgraded to return probabilities) --- def predict_sentiment(text): if not text.strip(): return None, None inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True) with torch.no_grad(): logits = model(**inputs).logits probabilities = torch.nn.functional.softmax(logits, dim=-1)[0] predicted_class_id = probabilities.argmax().item() return labels[predicted_class_id], probabilities.numpy() # --- Building the User Interface --- # Custom CSS for a cool look st.markdown(""" """, unsafe_allow_html=True) # --- THIS IS THE NEW, UPGRADED TITLE SECTION --- st.markdown("