CananD commited on
Commit
1c64d1f
·
verified ·
1 Parent(s): edf1d3a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load model with error handling
5
+ @st.cache_resource
6
+ def load_model():
7
+ try:
8
+ return pipeline('sentiment-analysis', model="distilbert-base-uncased-finetuned-sst-2-english")
9
+ except Exception as e:
10
+ st.error(f"Model loading failed: {str(e)}")
11
+ st.stop()
12
+
13
+ classifier = load_model()
14
+
15
+ # Streamlit UI
16
+ st.title("CPU Sentiment Analysis")
17
+ user_input = st.text_area("Enter text to analyze:", "I love this simple version!")
18
+
19
+ if st.button("Analyze"):
20
+ if user_input:
21
+ try:
22
+ result = classifier(user_input)
23
+ st.subheader("Result:")
24
+ emoji = "😊" if result[0]['label'] == 'POSITIVE' else "😞"
25
+ st.write(f"{emoji} **{result[0]['label']}** (confidence: {result[0]['score']:.2%})")
26
+ except Exception as e:
27
+ st.error(f"Analysis failed: {str(e)}")
28
+ else:
29
+ st.warning("Please enter some text first!")