khadija3818 commited on
Commit
dafef37
1 Parent(s): f215cbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -1,28 +1,30 @@
1
  import streamlit as st
2
- from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
3
 
4
- # Load the emotion text classification model
5
- model_name = "danielferreira/emotion-text-classification"
6
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- emotion_classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
 
 
 
 
9
 
10
  # Streamlit web app
11
  def main():
12
- st.title("Emotion Text Classification App")
13
 
14
  # Input text area
15
  user_input = st.text_area("Enter text:", "Type or paste your text here...")
16
 
17
- # Button to trigger classification
18
- if st.button("Classify Text Emotion"):
19
- # Classification result
20
- classification_result = emotion_classifier(user_input)
21
-
22
  # Display the result
23
- st.write("Predicted Emotion:", classification_result[0]['label'])
24
- st.write("Score:", classification_result[0]['score'])
25
 
26
  # Run the app
27
  if __name__ == "__main__":
28
- main()
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # Load the sentiment analysis model from Hugging Face
5
+ sentiment_analysis = pipeline("sentiment-analysis")
6
+
7
+ # Function to get sentiment prediction
8
+ def predict_sentiment(text):
9
+ result = sentiment_analysis(text)
10
+ label = result[0]['label']
11
+ score = result[0]['score']
12
+ return label, score
13
 
14
  # Streamlit web app
15
  def main():
16
+ st.title("Sentiment Analysis App")
17
 
18
  # Input text area
19
  user_input = st.text_area("Enter text:", "Type or paste your text here...")
20
 
21
+ # Button to trigger sentiment prediction
22
+ if st.button("Predict Sentiment"):
 
 
 
23
  # Display the result
24
+ sentiment_label, sentiment_score = predict_sentiment(user_input)
25
+ st.write(f"Sentiment: {sentiment_label}, Score: {sentiment_score:.4f}")
26
 
27
  # Run the app
28
  if __name__ == "__main__":
29
+ main()
30
+