Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Title and description
|
5 |
+
st.title("Sentiment Analysis")
|
6 |
+
st.write("This application performs text classification using a pre-trained Hugging Face model.")
|
7 |
+
|
8 |
+
# Define the model and pipeline
|
9 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
10 |
+
classifier = pipeline("sentiment-analysis", model=model_name)
|
11 |
+
|
12 |
+
# Get user input
|
13 |
+
user_input = st.text_area("Enter text:", placeholder="Type your text here...")
|
14 |
+
|
15 |
+
# Analyze and display results
|
16 |
+
if st.button("Analyze"):
|
17 |
+
if user_input.strip():
|
18 |
+
result = classifier(user_input)
|
19 |
+
st.write(f"**Result:** {result[0]['label']} ({result[0]['score']:.2f})")
|
20 |
+
else:
|
21 |
+
st.warning("Please enter some text.")
|