First_App / app.py
Gamer-Dude-77's picture
Create app.py
b30e524 verified
Raw
History Blame Contribute Delete
1.81 kB
# app.py
import streamlit as st
from transformers import pipeline
# Title
st.title("🎬 Movie Review Sentiment Classifier")
# Load model from Hugging Face Hub
@st.cache_resource
def load_model():
return pipeline("sentiment-analysis", model="Gamer-Dude-77/my-imdb-sentiment-model")
classifier = load_model()
# Text input
st.subheader("Enter a Review")
text_input = st.text_area("Type or paste your movie review below:", height=150)
# Prediction
if st.button("Analyze Sentiment"):
if text_input.strip():
results = classifier([text_input])
result = results[0]
st.write("### πŸ“Š Prediction Result")
if result["label"].upper() == "POSITIVE":
st.success(f"πŸ˜€ Positive (Confidence: {result['score']:.4f})")
elif result["label"].upper() == "NEGATIVE":
st.error(f"😞 Negative (Confidence: {result['score']:.4f})")
else:
st.info(f"😐 Neutral (Confidence: {result['score']:.4f})")
else:
st.warning("⚠️ Please enter some text to analyze.")
# Batch testing
st.subheader("Batch Testing")
uploaded_file = st.file_uploader("Upload a .txt file with one review per line", type=["txt"])
if uploaded_file is not None:
lines = uploaded_file.read().decode("utf-8").splitlines()
if st.button("Analyze File"):
results = classifier(lines)
for review, res in zip(lines, results):
if res["label"].upper() == "POSITIVE":
st.success(f"Review: {review}\nβ†’ πŸ˜€ Positive ({res['score']:.4f})")
elif res["label"].upper() == "NEGATIVE":
st.error(f"Review: {review}\nβ†’ 😞 Negative ({res['score']:.4f})")
else:
st.info(f"Review: {review}\nβ†’ 😐 Neutral ({res['score']:.4f})")
st.markdown("---")