Spaces:
Sleeping
Sleeping
| # app.py | |
| import streamlit as st | |
| from transformers import pipeline | |
| # Title | |
| st.title("π¬ Movie Review Sentiment Classifier") | |
| # Load model from Hugging Face Hub | |
| 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("---") | |