Spaces:
Runtime error
Runtime error
Jeffrey Rathgeber Jr
commited on
test model loading
Browse files
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 |
-
|
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 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
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 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
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 |
#------------------------------------------------------------------------
|