rb757 commited on
Commit
735918f
·
1 Parent(s): 6652808

Update app.py for improved UI

Browse files
Files changed (2) hide show
  1. app.py +25 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Title of the app
5
+ st.title("Sentiment Analysis App") #Sets the title of the Streamlit app to "Sentiment Analysis App".
6
+
7
+ # Input text from the user
8
+ user_input = st.text_area("Enter text to analyze") #Creates a text area where users can input the text they want to analyze.
9
+
10
+ # Select pretrained model
11
+ #distilbert-base-uncased-finetuned-sst-2-english: A DistilBERT model fine-tuned for sentiment analysis on the SST-2 dataset.
12
+ #nlptown/bert-base-multilingual-uncased-sentiment: A BERT model trained for sentiment analysis on multiple languages.
13
+
14
+ model_name = st.selectbox("Select a pretrained model", ["distilbert-base-uncased-finetuned-sst-2-english", "nlptown/bert-base-multilingual-uncased-sentiment"]) #Provides a dropdown menu for users to select a pretrained model provided by the HuggingFace Transformers library
15
+
16
+ # Initialize the sentiment analysis pipeline
17
+ sentiment_analysis = pipeline("sentiment-analysis", model=model_name,device=-1) #Initializes the sentiment analysis pipeline using the selected model.
18
+
19
+ # Perform sentiment analysis when the button is clicked
20
+ if st.button("Analyze"): #reates a button labeled "Analyze". When clicked, it triggers the sentiment analysis.
21
+ if user_input:
22
+ results = sentiment_analysis(user_input) #If text is entered, the sentiment analysis pipeline processes the text
23
+ st.write(results) #results are displayed
24
+ else:
25
+ st.write("Please enter some text to analyze") #If no text is entered, a message prompting the user to enter some text is displayed
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ transformers
3
+ torch
4
+ torchaudio
5
+ torchvision