balnur
commited on
Commit
·
526b8c5
1
Parent(s):
f897d1b
main
Browse files- app.py +25 -7
- requirements.txt +3 -0
app.py
CHANGED
@@ -1,11 +1,29 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
x = st.slider('Select a value')
|
9 |
|
10 |
-
st.write(
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
print("Loading the model...")
|
5 |
+
|
6 |
+
# Title and Description
|
7 |
|
8 |
+
st.title("Sentiment Analysis Web App")
|
|
|
9 |
|
10 |
+
st.write("""
|
11 |
+
### Powered by Hugging Face and Streamlit
|
12 |
+
This app uses a pre-trained NLP model from Hugging Face to analyze the sentiment of the text you enter.
|
13 |
+
Try entering a sentence to see if it's positive, negative, or neutral!
|
14 |
+
""")
|
15 |
+
# Initialize Hugging Face Sentiment Analysis Pipeline
|
16 |
+
@st.cache_resource
|
17 |
+
def load_model():
|
18 |
+
print("before load model")
|
19 |
+
return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
20 |
+
sentiment_analyzer = load_model()
|
21 |
+
# Input Text from User
|
22 |
+
user_input = st.text_area("Enter some text to analyze:", "Streamlit and Hugging Face make NLP fun!")
|
23 |
+
# Analyze Sentiment
|
24 |
+
if st.button("Analyze Sentiment"):
|
25 |
+
print("button click")
|
26 |
+
if user_input.strip():
|
27 |
+
result = sentiment_analyzer(user_input) [0]
|
28 |
+
sentiment result["label"]
|
29 |
+
score = result['score']
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit=1.14.1
|
2 |
+
transformers
|
3 |
+
torch
|