isom5240 commited on
Commit
c5302a0
·
verified ·
1 Parent(s): f8707dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -1,33 +1,20 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- from transformers import AutoModelForSequenceClassification
4
- from transformers import AutoTokenizer
5
- import torch
6
- import numpy as np
7
 
8
  def main():
9
- st.title("Test finetuned model with Yelp Review")
10
- st.write("Enter a sentence for analysis:")
 
 
11
 
12
  user_input = st.text_input("")
13
  if user_input:
14
- # Approach: AutoModel
15
- model2 = AutoModelForSequenceClassification.from_pretrained("isom5240/2025SpL2yelp",
16
- num_labels=5)
17
- tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
18
-
19
- inputs = tokenizer(user_input,
20
- padding=True,
21
- truncation=True,
22
- return_tensors='pt')
23
-
24
- outputs = model2(**inputs)
25
- predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
26
- predictions = predictions.cpu().detach().numpy()
27
- # Get the index of the largest output value
28
- max_index = np.argmax(predictions)
29
- st.write(f"result (AutoModel) - Label: {max_index}")
30
 
 
 
31
 
32
  if __name__ == "__main__":
33
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline
 
 
 
 
3
 
4
  def main():
5
+ sentiment_pipeline = pipeline(model="isom5240/2025SpringL2")
6
+
7
+ st.title("Sentiment Analysis with HuggingFace Spaces")
8
+ st.write("Enter a sentence to analyze its sentiment:")
9
 
10
  user_input = st.text_input("")
11
  if user_input:
12
+ result = sentiment_pipeline(user_input)
13
+ sentiment = result[0]["label"]
14
+ confidence = result[0]["score"]
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ st.write(f"Sentiment: {sentiment}")
17
+ st.write(f"Confidence: {confidence:.2f}")
18
 
19
  if __name__ == "__main__":
20
  main()