File size: 2,538 Bytes
ee42707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
import streamlit as st
from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
from functions import preprocess, sentiment_analysis, map_sentiment_score_to_rating


def render_home(model, tokenizer):
    st.title("Movie Review App")
    st.write("Welcome to our Movie Review App powered by the state-of-the-art  TinyBERT model with an impressive accuracy score of  0.86 respectively. Get ready to dive into the world of cinema and discover the sentiments behind your favorite movies. Whether it's a thrilling 9 or a heartwarming 3, our app not only predicts the sentiment but also rates the movie on a scale of 1 to 10. Express your thoughts, press 'Analyze,' and uncover the emotional depth of your movie review")
    st.image("Assets/movie_review.png", caption="", use_column_width=True)
    
    # Create a list to store comments
    comments = []
    
    
    
    # Input text area for the user to enter a review
    input_text = st.text_area("Write your movie review here...")

    # Output area for displaying sentiment
    if st.button("Analyze Review"):
        if input_text:
            # Perform sentiment analysis using the loaded model
            scores = sentiment_analysis(input_text, tokenizer, model)

            # Display sentiment scores
            st.text("Sentiment Scores:")
            for label, score in scores.items():
                st.text(f"{label}: {score:.2f}")

            # Determine the overall sentiment label
            sentiment_label = max(scores, key=scores.get)

            # Map sentiment labels to human-readable forms
            sentiment_mapping = {
                "Negative": "Negative",
                "Positive": "Positive"
            }
            sentiment_readable = sentiment_mapping.get(sentiment_label)

            # Display the sentiment label
            st.text(f"Sentiment: {sentiment_readable}")

            
            rating = map_sentiment_score_to_rating(scores[sentiment_label])

            # Convert the rating to an integer
            rating = int(rating)

            st.text(f"Rating: {rating}")            

    # Button to Clear the input text
    if st.button("Clear Input"):
        input_text = ""

    # Input area for adding comments
    new_comment = st.text_area("Add a comment:", "")
    if st.button("Submit Comment"):
        if new_comment:
            comments.append(new_comment)

        # Display the comments
        st.subheader("Comments")
        for comment in comments:
            st.write(comment)