Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
print(result)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the sentiment analysis pipeline
|
| 5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
|
| 7 |
+
# Streamlit interface
|
| 8 |
+
st.title("Sentiment Analysis with Hugging Face Transformers")
|
| 9 |
+
|
| 10 |
+
# Input text box
|
| 11 |
+
user_input = st.text_area("Enter text to analyze sentiment:", "I love using Hugging Face transformers!")
|
| 12 |
+
|
| 13 |
+
# Analyze sentiment button
|
| 14 |
+
if st.button("Analyze Sentiment"):
|
| 15 |
+
# Perform sentiment analysis
|
| 16 |
+
result = sentiment_pipeline(user_input)
|
| 17 |
+
|
| 18 |
+
# Display the result
|
| 19 |
+
sentiment = result[0]['label']
|
| 20 |
+
confidence = result[0]['score']
|
| 21 |
+
st.write(f"Sentiment: **{sentiment}**")
|
| 22 |
+
st.write(f"Confidence: **{confidence:.4f}**")
|
| 23 |
+
|
| 24 |
+
# To run the Streamlit app, use the command:
|
| 25 |
+
# streamlit run your_script_name.py
|
| 26 |
|
|
|