Spaces:
Runtime error
Runtime error
Commit
•
54cebbd
1
Parent(s):
3d53740
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment classifier model
|
5 |
+
distilled_student_sentiment_classifier = pipeline(
|
6 |
+
model="lxyuan/distilbert-base-multilingual-cased-sentiments-student",
|
7 |
+
return_all_scores=True
|
8 |
+
)
|
9 |
+
|
10 |
+
# Define the Streamlit app
|
11 |
+
def main():
|
12 |
+
# Add a title to the app
|
13 |
+
st.title("DistilBERT Sentiment Analysis")
|
14 |
+
|
15 |
+
# Add a text input field for user input
|
16 |
+
user_input = st.text_input("Enter text:")
|
17 |
+
|
18 |
+
# Perform sentiment analysis when the user submits input
|
19 |
+
if st.button("Analyze"):
|
20 |
+
# Perform sentiment analysis on the input text
|
21 |
+
result = distilled_student_sentiment_classifier(user_input)
|
22 |
+
|
23 |
+
# Display the sentiment analysis results
|
24 |
+
st.write("Sentiment Analysis Results:")
|
25 |
+
for item in result:
|
26 |
+
st.write(f"Label: {item['label']}, Score: {item['score']}")
|
27 |
+
|
28 |
+
# Run the Streamlit app
|
29 |
+
if __name__ == "__main__":
|
30 |
+
main()
|