import streamlit as st from transformers import pipeline import torch # Force CPU usage device = "cuda" if torch.cuda.is_available() else "cpu" model_name = "louiecerv/sentiment_analysis_model" classifier = pipeline("text-classification", model=model_name, tokenizer=model_name, device=0 if device == "cuda" else -1) print(f"Using device: {device}") # Streamlit UI st.title("Sentiment Analysis App") st.write("Enter a movie review and get its sentiment.") user_input = st.text_area("Enter review:") if st.button("Analyze"): if user_input: prediction = classifier(user_input) label = prediction[0]['label'] confidence = prediction[0]['score'] st.write(f"### Sentiment: {label}") st.write(f"Confidence: {confidence:.2f}") else: st.warning("Please enter a review.")