Jeffrey Rathgeber Jr commited on
Commit
26dac8d
·
unverified ·
1 Parent(s): 26f6079

test model loading

Browse files
Files changed (1) hide show
  1. app.py +42 -53
app.py CHANGED
@@ -8,62 +8,51 @@ import torch.nn.functional as F
8
 
9
  textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
10
 
11
- # option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'TextBlob', 'MILESTONE 3'))
12
- option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('MILESTONE 3', 'Pipeline'))
13
 
14
  st.write('You selected:', option)
15
 
16
  if option == 'MILESTONE 3':
17
- polarity = TextBlob(textIn).sentiment.polarity
18
- subjectivity = TextBlob(textIn).sentiment.subjectivity
19
- sentiment = ''
20
- if polarity < 0:
21
- sentiment = 'Negative'
22
- elif polarity == 0:
23
- sentiment = 'Neutral'
24
- else:
25
- sentiment = 'Positive'
26
- st.write('According to TextBlob, input text is ', sentiment, ' and a subjectivity score (from 0 being objective to 1 being subjective) of ', subjectivity)
27
 
28
- # model_name_0 = "Rathgeberj/milestone3_0"
29
- # model_0 = AutoModelForSequenceClassification.from_pretrained(model_name_0)
30
- # tokenizer_0 = AutoTokenizer.from_pretrained(model_name_0)
31
- # classifier_0 = pipeline(task="sentiment-analysis", model=model_0, tokenizer=tokenizer_0)
 
 
32
 
33
- # model_name_1 = "Rathgeberj/milestone3_1"
34
- # model_1 = AutoModelForSequenceClassification.from_pretrained(model_name_1)
35
- # tokenizer_1 = AutoTokenizer.from_pretrained(model_name_1)
36
- # classifier_1 = pipeline(task="sentiment-analysis", model=model_1, tokenizer=tokenizer_1)
37
 
38
- # model_name_2 = "Rathgeberj/milestone3_2"
39
- # model_2 = AutoModelForSequenceClassification.from_pretrained(model_name_2)
40
- # tokenizer_2 = AutoTokenizer.from_pretrained(model_name_2)
41
- # classifier_2 = pipeline(task="sentiment-analysis", model=model_2, tokenizer=tokenizer_2)
42
 
43
- # model_name_3 = "Rathgeberj/milestone3_3"
44
- # model_3 = AutoModelForSequenceClassification.from_pretrained(model_name_3)
45
- # tokenizer_3 = AutoTokenizer.from_pretrained(model_name_3)
46
- # classifier_3 = pipeline(task="sentiment-analysis", model=model_3, tokenizer=tokenizer_3)
47
 
48
- # model_name_4 = "Rathgeberj/milestone3_4"
49
- # model_4 = AutoModelForSequenceClassification.from_pretrained(model_name_4)
50
- # tokenizer_4 = AutoTokenizer.from_pretrained(model_name_4)
51
- # classifier_4 = pipeline(task="sentiment-analysis", model=model_4, tokenizer=tokenizer_4)
52
 
53
- # model_name_5 = "Rathgeberj/milestone3_5"
54
- # model_5 = AutoModelForSequenceClassification.from_pretrained(model_name_5)
55
- # tokenizer_5 = AutoTokenizer.from_pretrained(model_name_5)
56
- # classifier_5 = pipeline(task="sentiment-analysis", model=model_5, tokenizer=tokenizer_5)
57
 
58
- # models = [model_0, model_1, model_2, model_3, model_4, model_5]
59
- # tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
60
- # classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
61
 
62
  # X_train = [textIn]
63
  # batch = tokenizer(X_train, padding=True, truncation=True, max_length=512, return_tensors="pt")
64
-
65
-
66
- # st.write('TESTING2')
67
 
68
  if option == 'Pipeline':
69
 
@@ -75,17 +64,17 @@ if option == 'Pipeline':
75
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
76
  st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])
77
 
78
- # if option == 'TextBlob':
79
- # polarity = TextBlob(textIn).sentiment.polarity
80
- # subjectivity = TextBlob(textIn).sentiment.subjectivity
81
- # sentiment = ''
82
- # if polarity < 0:
83
- # sentiment = 'Negative'
84
- # elif polarity == 0:
85
- # sentiment = 'Neutral'
86
- # else:
87
- # sentiment = 'Positive'
88
- # st.write('According to TextBlob, input text is ', sentiment, ' and a subjectivity score (from 0 being objective to 1 being subjective) of ', subjectivity)
89
 
90
 
91
  #------------------------------------------------------------------------
 
8
 
9
  textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
10
 
11
+ option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('MILESTONE 3', 'Pipeline', 'TextBlob'))
 
12
 
13
  st.write('You selected:', option)
14
 
15
  if option == 'MILESTONE 3':
 
 
 
 
 
 
 
 
 
 
16
 
17
+ st.write('test1')
18
+
19
+ model_name_0 = "Rathgeberj/milestone3_0"
20
+ model_0 = AutoModelForSequenceClassification.from_pretrained(model_name_0)
21
+ tokenizer_0 = AutoTokenizer.from_pretrained(model_name_0)
22
+ classifier_0 = pipeline(task="sentiment-analysis", model=model_0, tokenizer=tokenizer_0)
23
 
24
+ model_name_1 = "Rathgeberj/milestone3_1"
25
+ model_1 = AutoModelForSequenceClassification.from_pretrained(model_name_1)
26
+ tokenizer_1 = AutoTokenizer.from_pretrained(model_name_1)
27
+ classifier_1 = pipeline(task="sentiment-analysis", model=model_1, tokenizer=tokenizer_1)
28
 
29
+ model_name_2 = "Rathgeberj/milestone3_2"
30
+ model_2 = AutoModelForSequenceClassification.from_pretrained(model_name_2)
31
+ tokenizer_2 = AutoTokenizer.from_pretrained(model_name_2)
32
+ classifier_2 = pipeline(task="sentiment-analysis", model=model_2, tokenizer=tokenizer_2)
33
 
34
+ model_name_3 = "Rathgeberj/milestone3_3"
35
+ model_3 = AutoModelForSequenceClassification.from_pretrained(model_name_3)
36
+ tokenizer_3 = AutoTokenizer.from_pretrained(model_name_3)
37
+ classifier_3 = pipeline(task="sentiment-analysis", model=model_3, tokenizer=tokenizer_3)
38
 
39
+ model_name_4 = "Rathgeberj/milestone3_4"
40
+ model_4 = AutoModelForSequenceClassification.from_pretrained(model_name_4)
41
+ tokenizer_4 = AutoTokenizer.from_pretrained(model_name_4)
42
+ classifier_4 = pipeline(task="sentiment-analysis", model=model_4, tokenizer=tokenizer_4)
43
 
44
+ model_name_5 = "Rathgeberj/milestone3_5"
45
+ model_5 = AutoModelForSequenceClassification.from_pretrained(model_name_5)
46
+ tokenizer_5 = AutoTokenizer.from_pretrained(model_name_5)
47
+ classifier_5 = pipeline(task="sentiment-analysis", model=model_5, tokenizer=tokenizer_5)
48
 
49
+ models = [model_0, model_1, model_2, model_3, model_4, model_5]
50
+ tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
51
+ classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
52
 
53
  # X_train = [textIn]
54
  # batch = tokenizer(X_train, padding=True, truncation=True, max_length=512, return_tensors="pt")
55
+ st.write('test2')
 
 
56
 
57
  if option == 'Pipeline':
58
 
 
64
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
65
  st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])
66
 
67
+ if option == 'TextBlob':
68
+ polarity = TextBlob(textIn).sentiment.polarity
69
+ subjectivity = TextBlob(textIn).sentiment.subjectivity
70
+ sentiment = ''
71
+ if polarity < 0:
72
+ sentiment = 'Negative'
73
+ elif polarity == 0:
74
+ sentiment = 'Neutral'
75
+ else:
76
+ sentiment = 'Positive'
77
+ st.write('According to TextBlob, input text is ', sentiment, ' and a subjectivity score (from 0 being objective to 1 being subjective) of ', subjectivity)
78
 
79
 
80
  #------------------------------------------------------------------------