isom5240 commited on
Commit
5955eee
·
verified ·
1 Parent(s): 23b1c3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -1,23 +1,35 @@
1
  import streamlit as st
 
2
  from transformers import AutoModelForSequenceClassification
3
  from transformers import AutoTokenizer
4
  import torch
5
  import numpy as np
6
 
7
  def main():
 
 
8
  st.title("yelp2024fall Test")
9
  st.write("Enter a sentence for analysis:")
 
10
  user_input = st.text_input("")
11
  if user_input:
12
  # Approach: AutoModel
13
  model2 = AutoModelForSequenceClassification.from_pretrained("isom5240/CustomModel_yelp2024fall",
14
  num_labels=5)
15
  tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
 
 
 
 
 
 
16
  outputs = model2(**inputs)
17
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
18
  predictions = predictions.cpu().detach().numpy()
19
  # Get the index of the largest output value
20
  max_index = np.argmax(predictions)
21
  st.write(f"result (AutoModel) - Label: {max_index}")
 
 
22
  if __name__ == "__main__":
23
- main()
 
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
+
10
+
11
  st.title("yelp2024fall Test")
12
  st.write("Enter a sentence for analysis:")
13
+
14
  user_input = st.text_input("")
15
  if user_input:
16
  # Approach: AutoModel
17
  model2 = AutoModelForSequenceClassification.from_pretrained("isom5240/CustomModel_yelp2024fall",
18
  num_labels=5)
19
  tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
20
+
21
+ inputs = tokenizer(user_input,
22
+ padding=True,
23
+ truncation=True,
24
+ return_tensors='pt')
25
+
26
  outputs = model2(**inputs)
27
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
28
  predictions = predictions.cpu().detach().numpy()
29
  # Get the index of the largest output value
30
  max_index = np.argmax(predictions)
31
  st.write(f"result (AutoModel) - Label: {max_index}")
32
+
33
+
34
  if __name__ == "__main__":
35
+ main()