Spaces:
Sleeping
Sleeping
Yereque
commited on
Commit
·
f7b4690
1
Parent(s):
2421d73
classifaction
Browse files- app.py +47 -0
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
print("Loading the model...")
|
| 5 |
+
|
| 6 |
+
# Title and Description
|
| 7 |
+
st.title("Sentiment Analysis Web App")
|
| 8 |
+
st.write("""
|
| 9 |
+
### Powered by Hugging Face and Streamlit
|
| 10 |
+
This app uses a pre-trained NLP model from Hugging Face to analyze the sentiment of the text you enter.
|
| 11 |
+
Try entering a sentence to see if it's positive, negative, or neutral!
|
| 12 |
+
""")
|
| 13 |
+
|
| 14 |
+
# Initialize Hugging Face Sentiment Analysis Pipeline
|
| 15 |
+
@st.cache_resource
|
| 16 |
+
def load_model():
|
| 17 |
+
print("before load model")
|
| 18 |
+
return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 19 |
+
|
| 20 |
+
sentiment_analyzer = load_model()
|
| 21 |
+
|
| 22 |
+
# Input Text from User
|
| 23 |
+
user_input = st.text_area("Enter some text to analyze:", "Streamlit and Hugging Face make NLP fun!")
|
| 24 |
+
|
| 25 |
+
# Analyze Sentiment
|
| 26 |
+
if st.button("Analyze Sentiment"):
|
| 27 |
+
print("button click")
|
| 28 |
+
if user_input.strip():
|
| 29 |
+
result = sentiment_analyzer(user_input)[0]
|
| 30 |
+
sentiment = result['label']
|
| 31 |
+
score = result['score']
|
| 32 |
+
|
| 33 |
+
# Display the Result
|
| 34 |
+
st.subheader("Sentiment Analysis Result")
|
| 35 |
+
st.write(f"**Sentiment:** {sentiment}")
|
| 36 |
+
st.write(f"**Confidence Score:** {score:.2f}")
|
| 37 |
+
else:
|
| 38 |
+
st.warning("Please enter some text to analyze!")
|
| 39 |
+
|
| 40 |
+
# Sidebar with About Information
|
| 41 |
+
st.sidebar.title("About")
|
| 42 |
+
st.sidebar.info("""
|
| 43 |
+
This app demonstrates the use of Hugging Face's NLP models with Streamlit.
|
| 44 |
+
It uses the distilbert-base-uncased-finetuned-sst-2-english model for sentiment analysis.
|
| 45 |
+
""")
|
| 46 |
+
|
| 47 |
+
print('after')
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.41.1
|
| 2 |
+
transformers
|
| 3 |
+
torch
|