File size: 1,813 Bytes
b30e524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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("---")