Spaces:
Running
Running
Commit
·
d796673
1
Parent(s):
acfaf61
First version of space
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
label2stars = {
|
| 6 |
+
1: "⭐️",
|
| 7 |
+
2: "⭐️⭐️",
|
| 8 |
+
3: "⭐️⭐️⭐️",
|
| 9 |
+
4: "⭐️⭐️⭐️⭐️",
|
| 10 |
+
5: "⭐️⭐️⭐️⭐️⭐️",
|
| 11 |
+
"1 star": "⭐️",
|
| 12 |
+
"2 stars": "⭐️⭐️",
|
| 13 |
+
"3 stars": "⭐️⭐️⭐️",
|
| 14 |
+
"4 stars": "⭐️⭐️⭐️⭐️",
|
| 15 |
+
"5 stars": "⭐️⭐️⭐️⭐️⭐️",
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
@st.cache_resource
|
| 19 |
+
def load_model(model_id):
|
| 20 |
+
return pipeline("sentiment-analysis", model=model_id)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
bert_model = load_model("nlptown/bert-base-multilingual-uncased-sentiment")
|
| 24 |
+
modernbert_model = load_model("nlptown/ModernBERT-base-sentiment-20241228")
|
| 25 |
+
|
| 26 |
+
st.title("NLP Town Sentiment Analysis")
|
| 27 |
+
|
| 28 |
+
example1 = "I have sensitive eyes and this is non-irritating. My eyes water a lot and that often leads to product getting into my eyes and causing stinging and or burning in the eye area. This cream has not bothered me at all."
|
| 29 |
+
example2 = "Very natural, light weight and good quality. I use on brides who are not used to lashes but still want a bit of length and definition."
|
| 30 |
+
example3 = "I have to admit that I'm very new to meditation and guided imagery, but I found the suggested imagery of a \"guardian\" closing the drapes in my bedroom and then sitting next to my bed while I was sleeping to be unnerving. I was wide awake at the end of the CD and was completely disappointed with this purchase. I'm glad that I am able to return it."
|
| 31 |
+
example4 = "Catchy promises, little delivery."
|
| 32 |
+
|
| 33 |
+
option = st.selectbox("Examples", [example1, example2, example3, example4], index=None, placeholder='Select an example or enter your text below')
|
| 34 |
+
|
| 35 |
+
query = st.text_area("Enter your text here", value=option)
|
| 36 |
+
click = st.button("Analyze", type="primary")
|
| 37 |
+
|
| 38 |
+
if query or click:
|
| 39 |
+
|
| 40 |
+
bert_result = bert_model(query)[0]
|
| 41 |
+
modernbert_result = modernbert_model(query)[0]
|
| 42 |
+
|
| 43 |
+
col1, col2 = st.columns([3, 1])
|
| 44 |
+
|
| 45 |
+
with col1:
|
| 46 |
+
st.write("[nlptown/bert-base-multilingual-uncased-sentiment](https://huggingface.co/nlptown/bert-base-multilingual-uncased-sentiment):")
|
| 47 |
+
st.write("[nlptown/ModernBERT-base-sentiment](https://www.nlp.town):")
|
| 48 |
+
|
| 49 |
+
with col2:
|
| 50 |
+
st.write(label2stars[bert_result['label']])
|
| 51 |
+
st.write(label2stars[modernbert_result['label']])
|