rararara9999 commited on
Commit
459f9e5
·
verified ·
1 Parent(s): 86023b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -1,18 +1,29 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
3
  def main():
4
- sentiment_pipeline = pipeline("sentiment-analysis",model="microsoft/resnet-50")
5
- st.title("Sentiment Analysis with HuggingFace Spaces")
6
- st.write("Enter a sentence to analyze its sentiment:")
7
- user_input = st.text_input("")
8
- if user_input:
9
- result = sentiment_pipeline(user_input)
10
- sentiment = result["label"]
11
- confidence = result["score"]
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- st.write(f"Sentiment: {sentiment}")
14
- st.write(f"Confidence: {confidence:.2f}")
15
  if __name__ == "__main__":
16
- main()
 
17
 
18
 
 
1
  import streamlit as st
2
+ from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
3
+
4
  def main():
5
+ # Load the model and tokenizer
6
+ model_name = "microsoft/resnet-50"
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+
10
+ # Initialize the pipeline
11
+ sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
12
+
13
+ st.title("Sentiment Analysis with HuggingFace Spaces")
14
+ st.write("Enter a sentence to analyze its sentiment:")
15
+
16
+ user_input = st.text_input("")
17
+ if user_input:
18
+ result = sentiment_pipeline(user_input)
19
+ sentiment = result["label"]
20
+ confidence = result["score"]
21
+
22
+ st.write(f"Sentiment: {sentiment}")
23
+ st.write(f"Confidence: {confidence:.2f}")
24
 
 
 
25
  if __name__ == "__main__":
26
+ main()
27
+
28
 
29