Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
|
5 |
+
# Load the Sentence Transformers model
|
6 |
+
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
7 |
+
|
8 |
+
# Load the sentiment analysis model
|
9 |
+
classifier = pipeline("sentiment-analysis", model="Suphawan/website_classification")
|
10 |
+
|
11 |
+
def main():
|
12 |
+
st.title("Website classification")
|
13 |
+
|
14 |
+
with st.form("text_field"):
|
15 |
+
text = st.text_area('Enter some text:')
|
16 |
+
# clicked will be True only when the button is clicked
|
17 |
+
clicked = st.form_submit_button("Submit text")
|
18 |
+
|
19 |
+
if clicked:
|
20 |
+
# Perform sentiment analysis
|
21 |
+
sentiment_results = classifier([text])
|
22 |
+
sentiment = sentiment_results[0]['label']
|
23 |
+
confidence = sentiment_results[0]['score']
|
24 |
+
|
25 |
+
# Compute sentence embeddings
|
26 |
+
sentence_embeddings = model.encode([text])
|
27 |
+
|
28 |
+
st.write("Sentiment:", sentiment)
|
29 |
+
st.write("Confidence:", confidence)
|
30 |
+
st.write("Sentence Embeddings:", sentence_embeddings)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
altair<5
|