Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment analysis model from Hugging Face
|
5 |
+
classifier = pipeline('sentiment-analysis')
|
6 |
+
|
7 |
+
# Create a Streamlit app
|
8 |
+
st.title('Sentiment Analysis with Hugging Face')
|
9 |
+
st.write('Enter some text and we will predict its sentiment!')
|
10 |
+
|
11 |
+
# Add a text input box for the user to enter text
|
12 |
+
text_input = st.text_input('Enter text here')
|
13 |
+
|
14 |
+
# When the user submits text, run the sentiment analysis model on it
|
15 |
+
if st.button('Submit'):
|
16 |
+
# Predict the sentiment of the text using the Hugging Face model
|
17 |
+
sentiment = classifier(text_input)[0]['label']
|
18 |
+
|
19 |
+
# Display the sentiment prediction to the user
|
20 |
+
st.write(f'Sentiment: {sentiment}')
|
21 |
+
|