Commit
·
ee42707
1
Parent(s):
c302b1e
Create home.py
Browse files
home.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
|
3 |
+
from functions import preprocess, sentiment_analysis, map_sentiment_score_to_rating
|
4 |
+
|
5 |
+
|
6 |
+
def render_home(model, tokenizer):
|
7 |
+
st.title("Movie Review App")
|
8 |
+
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")
|
9 |
+
st.image("Assets/movie_review.png", caption="", use_column_width=True)
|
10 |
+
|
11 |
+
# Create a list to store comments
|
12 |
+
comments = []
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
# Input text area for the user to enter a review
|
17 |
+
input_text = st.text_area("Write your movie review here...")
|
18 |
+
|
19 |
+
# Output area for displaying sentiment
|
20 |
+
if st.button("Analyze Review"):
|
21 |
+
if input_text:
|
22 |
+
# Perform sentiment analysis using the loaded model
|
23 |
+
scores = sentiment_analysis(input_text, tokenizer, model)
|
24 |
+
|
25 |
+
# Display sentiment scores
|
26 |
+
st.text("Sentiment Scores:")
|
27 |
+
for label, score in scores.items():
|
28 |
+
st.text(f"{label}: {score:.2f}")
|
29 |
+
|
30 |
+
# Determine the overall sentiment label
|
31 |
+
sentiment_label = max(scores, key=scores.get)
|
32 |
+
|
33 |
+
# Map sentiment labels to human-readable forms
|
34 |
+
sentiment_mapping = {
|
35 |
+
"Negative": "Negative",
|
36 |
+
"Positive": "Positive"
|
37 |
+
}
|
38 |
+
sentiment_readable = sentiment_mapping.get(sentiment_label)
|
39 |
+
|
40 |
+
# Display the sentiment label
|
41 |
+
st.text(f"Sentiment: {sentiment_readable}")
|
42 |
+
|
43 |
+
|
44 |
+
rating = map_sentiment_score_to_rating(scores[sentiment_label])
|
45 |
+
|
46 |
+
# Convert the rating to an integer
|
47 |
+
rating = int(rating)
|
48 |
+
|
49 |
+
st.text(f"Rating: {rating}")
|
50 |
+
|
51 |
+
# Button to Clear the input text
|
52 |
+
if st.button("Clear Input"):
|
53 |
+
input_text = ""
|
54 |
+
|
55 |
+
# Input area for adding comments
|
56 |
+
new_comment = st.text_area("Add a comment:", "")
|
57 |
+
if st.button("Submit Comment"):
|
58 |
+
if new_comment:
|
59 |
+
comments.append(new_comment)
|
60 |
+
|
61 |
+
# Display the comments
|
62 |
+
st.subheader("Comments")
|
63 |
+
for comment in comments:
|
64 |
+
st.write(comment)
|