Spaces:
Sleeping
Sleeping
app updated
Browse files
app.py
CHANGED
@@ -1,29 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
|
|
4 |
|
5 |
|
6 |
# Define the function for sentiment analysis
|
7 |
@st.cache_resource
|
8 |
-
def
|
9 |
# Load the model and tokenizer
|
10 |
-
model = AutoModelForSequenceClassification.from_pretrained("MrDdz/mytuned_test_trainer-base-cased1")
|
11 |
tokenizer = AutoTokenizer.from_pretrained("xlnet-base-cased")
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# Setting the page configurations
|
21 |
-
st.set_page_config(
|
22 |
-
page_title="Sentiment Analysis App",
|
23 |
-
page_icon=":smile:",
|
24 |
-
layout="wide",
|
25 |
-
initial_sidebar_state="auto",
|
26 |
-
)
|
27 |
|
28 |
# Add description and title
|
29 |
st.write("""
|
@@ -37,6 +32,13 @@ image = st.image("images.png", width=200)
|
|
37 |
# Get user input
|
38 |
text = st.text_input("Type here:")
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# Define the CSS style for the app
|
41 |
st.markdown(
|
42 |
"""
|
@@ -53,11 +55,18 @@ unsafe_allow_html=True
|
|
53 |
)
|
54 |
|
55 |
# Show sentiment output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
if text:
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
else:
|
63 |
-
st.warning(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
+
import numpy as np
|
5 |
|
6 |
|
7 |
# Define the function for sentiment analysis
|
8 |
@st.cache_resource
|
9 |
+
def get_model():
|
10 |
# Load the model and tokenizer
|
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained("xlnet-base-cased")
|
12 |
+
model = AutoModelForSequenceClassification.from_pretrained("MrDdz/mytuned_test_trainer-base-cased1")
|
13 |
+
tokenizer, model = get_model()
|
14 |
|
15 |
+
# # Setting the page configurations
|
16 |
+
# st.set_page_config(
|
17 |
+
# page_title="Sentiment Analysis App",
|
18 |
+
# page_icon=":smile:",
|
19 |
+
# layout="wide",
|
20 |
+
# initial_sidebar_state="auto",
|
21 |
+
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Add description and title
|
24 |
st.write("""
|
|
|
32 |
# Get user input
|
33 |
text = st.text_input("Type here:")
|
34 |
|
35 |
+
d = {
|
36 |
+
|
37 |
+
0:'Negative',
|
38 |
+
1:'Neutral',
|
39 |
+
2: 'Positive'
|
40 |
+
|
41 |
+
}
|
42 |
# Define the CSS style for the app
|
43 |
st.markdown(
|
44 |
"""
|
|
|
55 |
)
|
56 |
|
57 |
# Show sentiment output
|
58 |
+
# if text:
|
59 |
+
# sentiment, score = predict_sentiment(text)
|
60 |
+
# if sentiment == "Positive":
|
61 |
+
# st.success(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|
62 |
+
# elif sentiment == "Negative":
|
63 |
+
# st.error(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|
64 |
+
# else:
|
65 |
+
# st.warning(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|
66 |
+
|
67 |
if text:
|
68 |
+
text_sample = tokenizer([text], padding = True, Truncation = True, max_length = 512, return_tensors = 'pt' )
|
69 |
+
output = model(** text_sample)
|
70 |
+
st.write("Logits: ",output.logits)
|
71 |
+
y_pred = np.argmax(output.logits.detach().numpy(),axis =1)
|
72 |
+
st.write("Prediction :",d[y_pred[0]])
|
|
|
|