medelharchaoui commited on
Commit
bc6af51
1 Parent(s): c26118e

create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline from Hugging Face
5
+ nlp = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
6
+
7
+ # Streamlit app layout
8
+ st.title("Simple Sentiment Analysis")
9
+ st.write("This app uses a pre-trained model from Hugging Face to perform sentiment analysis on user input.")
10
+
11
+ # User input
12
+ user_input = st.text_area("Enter some text to analyze:", value="", height=150, max_chars=500)
13
+
14
+ if user_input:
15
+ # Perform sentiment analysis on the user input
16
+ result = nlp(user_input)
17
+
18
+ # Display the sentiment analysis result
19
+ sentiment = result[0]["label"]
20
+ confidence = result[0]["score"]
21
+
22
+ st.write(f"Sentiment: {sentiment}")
23
+ st.write(f"Confidence: {confidence:.2f}")
24
+ else:
25
+ st.write("Please enter some text to analyze.")