isom5240 commited on
Commit
f924742
·
verified ·
1 Parent(s): 1ac3b2e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ sentiment_pipeline = pipeline(model="isom5240/CustomModel_yelp2024fall")
16
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
17
+ outputs = model2(**inputs)
18
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
19
+ predictions = predictions.cpu().detach().numpy()
20
+ # Get the index of the largest output value
21
+ max_index = np.argmax(predictions)
22
+ st.write(f"result (AutoModel) - Label: {max_index}")
23
+ if __name__ == "__main__":
24
+ main()