Kuaaangwen commited on
Commit
9983408
·
1 Parent(s): 0567884

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -2,21 +2,23 @@
2
  import streamlit as st
3
  from transformers import pipeline
4
  from textblob import TextBlob
 
 
5
 
6
- pipe = pipeline('sentiment-analysis')
7
- st.title("Hugging Face Sentiment Analysis Spaces Example")
8
- st.subheader("What framework would you like to use for Sentiment Analysis")
9
- #Picking what NLP task you want to do
10
- option = st.selectbox('Framework',('Transformers', 'TextBlob')) #option is stored in this variable
11
- #Textbox for text user is entering
12
- st.subheader("Enter the text you'd like to analyze.")
13
- text = st.text_input('Enter text') #text is stored in this variable
14
-
15
- if option == 'Transformers':
16
- out = pipe(text)
17
- else:
18
- out = TextBlob(text)
19
- out = out.sentiment
20
- st.write("Sentiment of Text: ")
21
- st.write(out)
22
 
 
 
 
 
 
 
 
 
 
 
2
  import streamlit as st
3
  from transformers import pipeline
4
  from textblob import TextBlob
5
+ from sentence_transformers import SentenceTransformer
6
+ from sklearn.metrics.pairwise import cosine_similarity
7
 
8
+ sentences = \
9
+ [
10
+ "I have a bigger house than you",
11
+ "You have a bigger house than me"
12
+ ]
13
+
14
+ sentence_embeddings = model.encode(sentences)
 
 
 
 
 
 
 
 
 
15
 
16
+ for sentence, embedding in zip(sentences, sentence_embeddings):
17
+ print("Sentence:", sentence)
18
+ print("Embedding:", embedding)
19
+ print("")
20
+
21
+ print('Similarity between {} and {} is {}'.format(sentences[0],
22
+ sentences[1],
23
+ cosine_similarity(sentence_embeddings[0].reshape(1, -1),
24
+ sentence_embeddings[1].reshape(1, -1))[0][0]))