Spaces:
Sleeping
Sleeping
Create sentiment_analysis.py
Browse files- sentiment_analysis.py +26 -0
sentiment_analysis.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
# Use a pipeline as a high-level helper
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
+
text_classification = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
|
| 8 |
+
|
| 9 |
+
def sentment_classifiction(text):
|
| 10 |
+
output = text_classification(text)
|
| 11 |
+
return output[0]['label']
|
| 12 |
+
|
| 13 |
+
# Streamlit UI
|
| 14 |
+
def run():
|
| 15 |
+
st.title("Sentiment Analysis")
|
| 16 |
+
st.write("Enter a comment below to analyze its sentiment.")
|
| 17 |
+
|
| 18 |
+
text = st.text_area("Enter your text here:", "")
|
| 19 |
+
if st.button("Analyze"):
|
| 20 |
+
if text:
|
| 21 |
+
with st.spinner("Analyzing the text..."):
|
| 22 |
+
result = sentment_classifiction(text)
|
| 23 |
+
|
| 24 |
+
st.success(f"**Sentiment:** {result}")
|
| 25 |
+
else:
|
| 26 |
+
st.warning("⚠️ Please enter some text for analysis.")
|