Spaces:
Runtime error
Runtime error
Jeffrey Rathgeber Jr
commited on
test while loop
Browse files
app.py
CHANGED
@@ -10,7 +10,71 @@ 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: FINE-TUNED'))
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
#------------------------------------------------------------------------
|
@@ -38,72 +102,4 @@ st.write('You selected:', option)
|
|
38 |
# tokenizer = AutoTokenizer.from_pretrained(save_directory)
|
39 |
# model = AutoModelForSequenceClassification.from_pretrained(save_directory)
|
40 |
|
41 |
-
#------------------------------------------------------------------------
|
42 |
-
|
43 |
-
if option == 'Pipeline':
|
44 |
-
|
45 |
-
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
46 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
47 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
48 |
-
classifier = pipeline(task="sentiment-analysis", model=model, tokenizer=tokenizer)
|
49 |
-
|
50 |
-
# pipeline
|
51 |
-
preds = classifier(textIn)
|
52 |
-
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
53 |
-
st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])
|
54 |
-
|
55 |
-
if option == 'TextBlob':
|
56 |
-
# textblob
|
57 |
-
polarity = TextBlob(textIn).sentiment.polarity
|
58 |
-
subjectivity = TextBlob(textIn).sentiment.subjectivity
|
59 |
-
sentiment = ''
|
60 |
-
if polarity < 0:
|
61 |
-
sentiment = 'Negative'
|
62 |
-
elif polarity == 0:
|
63 |
-
sentiment = 'Neutral'
|
64 |
-
else:
|
65 |
-
sentiment = 'Positive'
|
66 |
-
|
67 |
-
st.write('According to TextBlob, input text is ', sentiment, ' and a subjectivity score (from 0 being objective to 1 being subjective) of ', subjectivity)
|
68 |
-
|
69 |
-
|
70 |
-
if option == 'MILESTONE 3: FINE-TUNED':
|
71 |
-
|
72 |
-
st.write('TESTING1')
|
73 |
-
|
74 |
-
# model_name_0 = "Rathgeberj/milestone3_0"
|
75 |
-
# model_0 = AutoModelForSequenceClassification.from_pretrained(model_name_0)
|
76 |
-
# tokenizer_0 = AutoTokenizer.from_pretrained(model_name_0)
|
77 |
-
# classifier_0 = pipeline(task="sentiment-analysis", model=model_0, tokenizer=tokenizer_0)
|
78 |
-
|
79 |
-
# model_name_1 = "Rathgeberj/milestone3_1"
|
80 |
-
# model_1 = AutoModelForSequenceClassification.from_pretrained(model_name_1)
|
81 |
-
# tokenizer_1 = AutoTokenizer.from_pretrained(model_name_1)
|
82 |
-
# classifier_1 = pipeline(task="sentiment-analysis", model=model_1, tokenizer=tokenizer_1)
|
83 |
-
|
84 |
-
# model_name_2 = "Rathgeberj/milestone3_2"
|
85 |
-
# model_2 = AutoModelForSequenceClassification.from_pretrained(model_name_2)
|
86 |
-
# tokenizer_2 = AutoTokenizer.from_pretrained(model_name_2)
|
87 |
-
# classifier_2 = pipeline(task="sentiment-analysis", model=model_2, tokenizer=tokenizer_2)
|
88 |
-
|
89 |
-
# model_name_3 = "Rathgeberj/milestone3_3"
|
90 |
-
# model_3 = AutoModelForSequenceClassification.from_pretrained(model_name_3)
|
91 |
-
# tokenizer_3 = AutoTokenizer.from_pretrained(model_name_3)
|
92 |
-
# classifier_3 = pipeline(task="sentiment-analysis", model=model_3, tokenizer=tokenizer_3)
|
93 |
-
|
94 |
-
# model_name_4 = "Rathgeberj/milestone3_4"
|
95 |
-
# model_4 = AutoModelForSequenceClassification.from_pretrained(model_name_4)
|
96 |
-
# tokenizer_4 = AutoTokenizer.from_pretrained(model_name_4)
|
97 |
-
# classifier_4 = pipeline(task="sentiment-analysis", model=model_4, tokenizer=tokenizer_4)
|
98 |
-
|
99 |
-
# model_name_5 = "Rathgeberj/milestone3_5"
|
100 |
-
# model_5 = AutoModelForSequenceClassification.from_pretrained(model_name_5)
|
101 |
-
# tokenizer_5 = AutoTokenizer.from_pretrained(model_name_5)
|
102 |
-
# classifier_5 = pipeline(task="sentiment-analysis", model=model_5, tokenizer=tokenizer_5)
|
103 |
-
|
104 |
-
# models = [model_0, model_1, model_2, model_3, model_4, model_5]
|
105 |
-
# tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
|
106 |
-
# classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
|
107 |
-
|
108 |
-
|
109 |
-
# st.write('TESTING2')
|
|
|
10 |
|
11 |
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'TextBlob', 'MILESTONE 3: FINE-TUNED'))
|
12 |
|
13 |
+
while True:
|
14 |
+
st.write('You selected:', option)
|
15 |
+
|
16 |
+
if option == 'MILESTONE 3: FINE-TUNED':
|
17 |
+
|
18 |
+
st.write('TESTING1')
|
19 |
+
|
20 |
+
# model_name_0 = "Rathgeberj/milestone3_0"
|
21 |
+
# model_0 = AutoModelForSequenceClassification.from_pretrained(model_name_0)
|
22 |
+
# tokenizer_0 = AutoTokenizer.from_pretrained(model_name_0)
|
23 |
+
# classifier_0 = pipeline(task="sentiment-analysis", model=model_0, tokenizer=tokenizer_0)
|
24 |
+
|
25 |
+
# model_name_1 = "Rathgeberj/milestone3_1"
|
26 |
+
# model_1 = AutoModelForSequenceClassification.from_pretrained(model_name_1)
|
27 |
+
# tokenizer_1 = AutoTokenizer.from_pretrained(model_name_1)
|
28 |
+
# classifier_1 = pipeline(task="sentiment-analysis", model=model_1, tokenizer=tokenizer_1)
|
29 |
+
|
30 |
+
# model_name_2 = "Rathgeberj/milestone3_2"
|
31 |
+
# model_2 = AutoModelForSequenceClassification.from_pretrained(model_name_2)
|
32 |
+
# tokenizer_2 = AutoTokenizer.from_pretrained(model_name_2)
|
33 |
+
# classifier_2 = pipeline(task="sentiment-analysis", model=model_2, tokenizer=tokenizer_2)
|
34 |
+
|
35 |
+
# model_name_3 = "Rathgeberj/milestone3_3"
|
36 |
+
# model_3 = AutoModelForSequenceClassification.from_pretrained(model_name_3)
|
37 |
+
# tokenizer_3 = AutoTokenizer.from_pretrained(model_name_3)
|
38 |
+
# classifier_3 = pipeline(task="sentiment-analysis", model=model_3, tokenizer=tokenizer_3)
|
39 |
+
|
40 |
+
# model_name_4 = "Rathgeberj/milestone3_4"
|
41 |
+
# model_4 = AutoModelForSequenceClassification.from_pretrained(model_name_4)
|
42 |
+
# tokenizer_4 = AutoTokenizer.from_pretrained(model_name_4)
|
43 |
+
# classifier_4 = pipeline(task="sentiment-analysis", model=model_4, tokenizer=tokenizer_4)
|
44 |
+
|
45 |
+
# model_name_5 = "Rathgeberj/milestone3_5"
|
46 |
+
# model_5 = AutoModelForSequenceClassification.from_pretrained(model_name_5)
|
47 |
+
# tokenizer_5 = AutoTokenizer.from_pretrained(model_name_5)
|
48 |
+
# classifier_5 = pipeline(task="sentiment-analysis", model=model_5, tokenizer=tokenizer_5)
|
49 |
+
|
50 |
+
# models = [model_0, model_1, model_2, model_3, model_4, model_5]
|
51 |
+
# tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
|
52 |
+
# classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
|
53 |
+
|
54 |
+
|
55 |
+
# st.write('TESTING2')
|
56 |
+
|
57 |
+
if option == 'Pipeline':
|
58 |
+
|
59 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
60 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
61 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
62 |
+
classifier = pipeline(task="sentiment-analysis", model=model, tokenizer=tokenizer)
|
63 |
+
preds = classifier(textIn)
|
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 |
#------------------------------------------------------------------------
|
|
|
102 |
# tokenizer = AutoTokenizer.from_pretrained(save_directory)
|
103 |
# model = AutoModelForSequenceClassification.from_pretrained(save_directory)
|
104 |
|
105 |
+
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|