Jeffrey Rathgeber Jr commited on
Commit
b9ff321
·
unverified ·
1 Parent(s): a7c7267

settingupthird

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -6,13 +6,6 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  import torch
7
  import torch.nn.functional as F
8
 
9
- model_name = "distilbert-base-uncased-finetuned-sst-2-english"
10
-
11
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
12
- tokenizer = AutoTokenizer.from_pretrained(model_name)
13
-
14
- classifier = pipeline(task="sentiment-analysis", model=model, tokenizer=tokenizer)
15
-
16
  textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
17
 
18
  option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'TextBlob', 'MILESTONE 3: FINE-TUNED'))
@@ -48,6 +41,12 @@ st.write('You selected:', option)
48
  #------------------------------------------------------------------------
49
 
50
  if option == 'Pipeline':
 
 
 
 
 
 
51
  # pipeline
52
  preds = classifier(textIn)
53
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
@@ -69,4 +68,11 @@ if option == 'TextBlob':
69
 
70
 
71
  if option == 'MILESTONE 3: FINE-TUNED':
72
- ...
 
 
 
 
 
 
 
 
6
  import torch
7
  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: FINE-TUNED'))
 
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]
 
68
 
69
 
70
  if option == 'MILESTONE 3: FINE-TUNED':
71
+ model_name = "distilbert-base-uncased-finetuned-sst-2-english"
72
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
73
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
74
+ classifier = pipeline(task="sentiment-analysis", model=model, tokenizer=tokenizer)
75
+ # pipeline
76
+ preds = classifier(textIn)
77
+ preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
78
+ st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])