rohitme890712 commited on
Commit
5ceef28
·
verified ·
1 Parent(s): 679f918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline
5
+ @st.cache_resource # Cache the pipeline for faster loading
6
+ def load_pipeline():
7
+ return pipeline("sentiment-analysis", model="distilbert-base-uncased")
8
+
9
+ sentiment_pipeline = load_pipeline()
10
+
11
+ # Streamlit app
12
+ st.title("Sentiment Analysis Tool")
13
+
14
+ # User input
15
+ text = st.text_area("Enter text to analyze:", "This is a great movie!")
16
+
17
+ # Analyze button
18
+ if st.button("Analyze"):
19
+ if text:
20
+ with st.spinner("Analyzing..."):
21
+ result = sentiment_pipeline(text)[0] # Get the first (and only) result
22
+ st.write("Sentiment:", result['label'])
23
+ st.write("Confidence:", result['score'])
24
+ else:
25
+ st.warning("Please enter some text to analyze.")