Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import numpy as np
|
|
5 |
import torch
|
6 |
from evaluate import load
|
7 |
|
8 |
-
#
|
9 |
try:
|
10 |
model = AutoModelForSequenceClassification.from_pretrained(
|
11 |
"tabularisai/multilingual-sentiment-analysis",
|
@@ -20,15 +20,15 @@ try:
|
|
20 |
tokenizer=tokenizer
|
21 |
)
|
22 |
except Exception as e:
|
23 |
-
st.error(f"
|
24 |
|
25 |
-
#
|
26 |
try:
|
27 |
kw_model = KeyBERT()
|
28 |
except Exception as e:
|
29 |
-
st.error(f"
|
30 |
|
31 |
-
#
|
32 |
label_map = {
|
33 |
"Very Negative": 0,
|
34 |
"Negative": 1,
|
@@ -37,21 +37,21 @@ label_map = {
|
|
37 |
"Very Positive": 4
|
38 |
}
|
39 |
|
40 |
-
# Streamlit
|
41 |
-
st.title("
|
42 |
|
43 |
-
#
|
44 |
-
input_text = st.text_area("
|
45 |
|
46 |
if input_text:
|
47 |
try:
|
48 |
-
#
|
49 |
result = sentiment_pipeline(input_text)
|
50 |
predicted_label = label_map[result[0]['label']]
|
51 |
-
rating = predicted_label + 1
|
52 |
confidence = result[0]['score']
|
53 |
|
54 |
-
#
|
55 |
keywords = kw_model.extract_keywords(
|
56 |
input_text,
|
57 |
keyphrase_ngram_range=(1, 2),
|
@@ -60,9 +60,9 @@ if input_text:
|
|
60 |
)
|
61 |
keyword_text = [kw[0] for kw in keywords]
|
62 |
|
63 |
-
#
|
64 |
-
st.write(f"
|
65 |
-
st.write(f"
|
66 |
-
st.write(f"
|
67 |
except Exception as e:
|
68 |
-
st.error(f"
|
|
|
5 |
import torch
|
6 |
from evaluate import load
|
7 |
|
8 |
+
# Load sentiment analysis model and word divider
|
9 |
try:
|
10 |
model = AutoModelForSequenceClassification.from_pretrained(
|
11 |
"tabularisai/multilingual-sentiment-analysis",
|
|
|
20 |
tokenizer=tokenizer
|
21 |
)
|
22 |
except Exception as e:
|
23 |
+
st.error(f"Error loading sentiment analysis model: {e}")
|
24 |
|
25 |
+
# Load keyword extraction model
|
26 |
try:
|
27 |
kw_model = KeyBERT()
|
28 |
except Exception as e:
|
29 |
+
st.error(f"Error loading sentiment analysis model: {e}")
|
30 |
|
31 |
+
# Define tag mapping
|
32 |
label_map = {
|
33 |
"Very Negative": 0,
|
34 |
"Negative": 1,
|
|
|
37 |
"Very Positive": 4
|
38 |
}
|
39 |
|
40 |
+
# Streamlit
|
41 |
+
st.title("Text emotion and keyword analysis")
|
42 |
|
43 |
+
# Create a text entry box
|
44 |
+
input_text = st.text_area("Please enter user feedback", "")
|
45 |
|
46 |
if input_text:
|
47 |
try:
|
48 |
+
# sentiment analysis
|
49 |
result = sentiment_pipeline(input_text)
|
50 |
predicted_label = label_map[result[0]['label']]
|
51 |
+
rating = predicted_label + 1
|
52 |
confidence = result[0]['score']
|
53 |
|
54 |
+
# ketwords extraction
|
55 |
keywords = kw_model.extract_keywords(
|
56 |
input_text,
|
57 |
keyphrase_ngram_range=(1, 2),
|
|
|
60 |
)
|
61 |
keyword_text = [kw[0] for kw in keywords]
|
62 |
|
63 |
+
# result showing
|
64 |
+
st.write(f"Rating: {rating}/5")
|
65 |
+
st.write(f"Confidence: {confidence:.2f}")
|
66 |
+
st.write(f"Key words: {', '.join(keyword_text)}")
|
67 |
except Exception as e:
|
68 |
+
st.error(f"Error while analyzing text: {e}")
|