Spaces:
Sleeping
Sleeping
Commit
·
1741e83
1
Parent(s):
09172e3
Update app.py
Browse files
app.py
CHANGED
@@ -1,107 +1,8 @@
|
|
1 |
-
# import streamlit as st
|
2 |
-
# from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
|
3 |
-
# from scipy.special import softmax
|
4 |
-
|
5 |
-
# # Load your model and tokenizer
|
6 |
-
# model_path = "petermutwiri/Tiny_Bert_Cupstone"
|
7 |
-
# tokenizer = AutoTokenizer.from_pretrained(model_path)
|
8 |
-
# model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
9 |
-
|
10 |
-
# # Preprocess text (username and link placeholders)
|
11 |
-
# #In summary, this preprocessing function helps ensure that usernames and links in the input text do not interfere with the sentiment analysis performed by the model. It replaces them with placeholder tokens to maintain the integrity of the text's structure while anonymizing or standardizing specific elements.
|
12 |
-
|
13 |
-
# def preprocess(text):
|
14 |
-
# new_text = []
|
15 |
-
# for t in text.split(" "):
|
16 |
-
# t = '@user' if t.startswith('@') and len(t) > 1 else t
|
17 |
-
# t = 'http' if t.startswith('http') else t
|
18 |
-
# new_text.append(t)
|
19 |
-
# return " ".join(new_text)
|
20 |
-
|
21 |
-
# def sentiment_analysis(text):
|
22 |
-
# text = preprocess(text)
|
23 |
-
|
24 |
-
# # PyTorch-based models
|
25 |
-
# encoded_input = tokenizer(text, return_tensors='pt')
|
26 |
-
# output = model(**encoded_input)
|
27 |
-
# scores_ = output[0][0].detach().numpy()
|
28 |
-
# scores_ = softmax(scores_)
|
29 |
-
|
30 |
-
# # Format output dict of scores
|
31 |
-
# labels = ['Negative', 'Positive']
|
32 |
-
# scores = {l: float(s) for (l, s) in zip(labels, scores_)}
|
33 |
-
|
34 |
-
# return scores
|
35 |
-
|
36 |
-
# # Streamlit app layout with two columns
|
37 |
-
# st.title("Movie Review App")
|
38 |
-
# st.write("Welcome to our Movie Review App powered by the state-of-the-art RoBERTa and TinyBERT models with an impressive accuracy score of 0.93 and 0.83 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")
|
39 |
-
# st.image("Assets/movie_review.png", caption="Sentiments examples", use_column_width=True)
|
40 |
-
|
41 |
-
# # Input text area for user to enter a tweet in the left column
|
42 |
-
# input_text = st.text_area("Write your movie review here...")
|
43 |
-
|
44 |
-
# # Output area for displaying sentiment in the right column
|
45 |
-
# if st.button("Analyze Review"):
|
46 |
-
# if input_text:
|
47 |
-
# # Perform movie review using the loaded model
|
48 |
-
# scores = sentiment_analysis(input_text)
|
49 |
-
|
50 |
-
# # Display sentiment scores in the right column
|
51 |
-
# st.text("Sentiment Scores:")
|
52 |
-
# for label, score in scores.items():
|
53 |
-
# st.text(f"{label}: {score:.2f}")
|
54 |
-
|
55 |
-
# # Determine the overall sentiment label
|
56 |
-
# sentiment_label = max(scores, key=scores.get)
|
57 |
-
|
58 |
-
# # Map sentiment labels to human-readable forms
|
59 |
-
# sentiment_mapping = {
|
60 |
-
# "Negative": "Negative",
|
61 |
-
# "Positive": "Positive"
|
62 |
-
# }
|
63 |
-
# sentiment_readable = sentiment_mapping.get(sentiment_label, "Unknown")
|
64 |
-
|
65 |
-
# # Display the sentiment label in the right column
|
66 |
-
# st.text(f"Sentiment: {sentiment_readable}")
|
67 |
-
|
68 |
-
# # Button to Clear the input text
|
69 |
-
# if st.button("Clear Input"):
|
70 |
-
# input_text = ""
|
71 |
-
|
72 |
import streamlit as st
|
73 |
from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
|
74 |
from home import render_home
|
75 |
from scipy.special import softmax
|
76 |
|
77 |
-
# # Define the preprocess function
|
78 |
-
# def preprocess(text):
|
79 |
-
# new_text = []
|
80 |
-
# for t in text.split(" "):
|
81 |
-
# t = '@user' if t.startswith('@') and len(t) > 1 else t
|
82 |
-
# t = 'http' if t.startsWith('http') else t
|
83 |
-
# new_text.append(t)
|
84 |
-
# return " ".join(new_text)
|
85 |
-
|
86 |
-
# # Define the sentiment_analysis function
|
87 |
-
# def sentiment_analysis(text, tokenizer, model):
|
88 |
-
# text = preprocess(text)
|
89 |
-
# encoded_input = tokenizer(text, return_tensors='pt')
|
90 |
-
# output = model(**encoded_input)
|
91 |
-
# scores_ = output[0][0].detach().numpy()
|
92 |
-
# scores_ = softmax(scores_)
|
93 |
-
# labels = ['Negative', 'Positive']
|
94 |
-
# scores = {l: float(s) for (l, s) in zip(labels, scores_)}
|
95 |
-
# return scores
|
96 |
-
|
97 |
-
# # Define the map_sentiment_score_to_rating function
|
98 |
-
# def map_sentiment_score_to_rating(score):
|
99 |
-
# min_score = 0.0
|
100 |
-
# max_score = 1.0
|
101 |
-
# min_rating = 1
|
102 |
-
# max_rating = 10
|
103 |
-
# rating = ((score - min_score) / (max_score - min_score)) * (max_rating - min_rating) + min_rating
|
104 |
-
# return rating
|
105 |
|
106 |
# Create a sidebar for navigation
|
107 |
st.sidebar.title("Navigation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
|
3 |
from home import render_home
|
4 |
from scipy.special import softmax
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Create a sidebar for navigation
|
8 |
st.sidebar.title("Navigation")
|