Spaces:
Sleeping
Sleeping
Commit
·
451cf27
0
Parent(s):
Initial commit of Sentiment Analysis App
Browse files- README.md +16 -0
- app.py +36 -0
- requirements.txt +3 -0
README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Sentiment Analysis App
|
| 3 |
+
emoji: 🤖
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.28.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Sentiment Analysis App
|
| 13 |
+
|
| 14 |
+
This is a simple Sentiment Analysis application built with [Streamlit](https://streamlit.io) and [Hugging Face Transformers](https://huggingface.co/docs/transformers).
|
| 15 |
+
|
| 16 |
+
It uses the default `distilbert-base-uncased-finetuned-sst-2-english` model to classify text as **POSITIVE** or **NEGATIVE**.
|
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Set page title and header
|
| 5 |
+
st.set_page_config(page_title="Sentiment Analysis App", page_icon="🤖")
|
| 6 |
+
st.title("🤖 Sentiment Analysis with Hugging Face")
|
| 7 |
+
|
| 8 |
+
st.markdown("""
|
| 9 |
+
This app uses a pre-trained machine learning model from Hugging Face Transformers to analyze the sentiment of your text.
|
| 10 |
+
""")
|
| 11 |
+
|
| 12 |
+
# Load the pipeline (cached to avoid reloading on every interaction)
|
| 13 |
+
@st.cache_resource
|
| 14 |
+
def load_sentiment_pipeline():
|
| 15 |
+
return pipeline("sentiment-analysis")
|
| 16 |
+
|
| 17 |
+
classifier = load_sentiment_pipeline()
|
| 18 |
+
|
| 19 |
+
# User input
|
| 20 |
+
text_input = st.text_area("Enter some text here:", height=150, placeholder="I love building cool AI apps!")
|
| 21 |
+
|
| 22 |
+
if st.button("Analyze Sentiment"):
|
| 23 |
+
if text_input.strip():
|
| 24 |
+
with st.spinner("Analyzing..."):
|
| 25 |
+
result = classifier(text_input)[0]
|
| 26 |
+
label = result['label']
|
| 27 |
+
score = result['score']
|
| 28 |
+
|
| 29 |
+
if label == 'POSITIVE':
|
| 30 |
+
st.success(f"**Sentiment:** {label} 😊")
|
| 31 |
+
else:
|
| 32 |
+
st.error(f"**Sentiment:** {label} 😔")
|
| 33 |
+
|
| 34 |
+
st.metric("Confidence Score", f"{score:.4f}")
|
| 35 |
+
else:
|
| 36 |
+
st.warning("Please enter some text to analyze.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|
| 3 |
+
torch
|