efecelik commited on
Commit
15f9a29
·
verified ·
1 Parent(s): 4c6d7c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -1,21 +1,31 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Title and description
5
- st.title("Sentiment Analysis")
6
- st.write("This application performs text classification using a pre-trained Hugging Face model.")
 
7
 
8
- # Define the model and pipeline
9
- model_name = "distilbert-base-uncased-finetuned-sst-2-english"
10
- classifier = pipeline("sentiment-analysis", model=model_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Get user input
13
- user_input = st.text_area("Enter text:", placeholder="Type your text here...")
14
-
15
- # Analyze and display results
16
- if st.button("Analyze"):
17
- if user_input.strip():
18
- result = classifier(user_input)
19
- st.write(f"**Result:** {result[0]['label']} ({result[0]['score']:.2f})")
20
- else:
21
- st.warning("Please enter some text.")
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Load the sentiment analysis pipeline
5
+ @st.cache_resource
6
+ def load_model():
7
+ return pipeline("sentiment-analysis")
8
 
9
+ def main():
10
+ st.title("Sentiment Analysis App")
11
+
12
+ # Create text input
13
+ user_input = st.text_area("Enter text for sentiment analysis:")
14
+
15
+ # Analyze button
16
+ if st.button("Analyze Sentiment"):
17
+ if user_input:
18
+ # Load model
19
+ sentiment_model = load_model()
20
+
21
+ # Perform sentiment analysis
22
+ result = sentiment_model(user_input)[0]
23
+
24
+ # Display results
25
+ st.write("Sentiment:", result['label'])
26
+ st.write("Confidence Score:", f"{result['score']:.2%}")
27
+ else:
28
+ st.warning("Please enter some text to analyze.")
29
 
30
+ if __name__ == "__main__":
31
+ main()