Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Title and Introduction
|
5 |
+
st.title("Sentiment Analysis App")
|
6 |
+
st.write("""
|
7 |
+
This app uses a Hugging Face model to analyze the sentiment of your text.
|
8 |
+
Type something below and click "Analyze Sentiment" to get started!
|
9 |
+
""")
|
10 |
+
|
11 |
+
# Text Input
|
12 |
+
user_input = st.text_area("Enter your text here:")
|
13 |
+
|
14 |
+
# Perform Sentiment Analysis
|
15 |
+
if st.button("Analyze Sentiment"):
|
16 |
+
if user_input.strip() == "":
|
17 |
+
st.warning("Please enter some text to analyze.")
|
18 |
+
else:
|
19 |
+
# Load the sentiment analysis pipeline
|
20 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
21 |
+
result = sentiment_pipeline(user_input)
|
22 |
+
|
23 |
+
# Extract and display results
|
24 |
+
sentiment = result[0]['label']
|
25 |
+
confidence = result[0]['score']
|
26 |
+
st.write(f"**Sentiment:** {sentiment}")
|
27 |
+
st.write(f"**Confidence Score:** {confidence:.2f}")
|