ayethuzar commited on
Commit
0dc667c
·
unverified ·
1 Parent(s): 1b6a720

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -11,13 +11,18 @@ form = st.form(key='sentiment-form')
11
  user_input = form.text_area(label = 'Enter your text', value = "I love steamlit and hugging face!")
12
  submit = form.form_submit_button('Submit')
13
 
14
- if submit:
15
- classifier = pipeline("sentiment-analysis") #using the pipeline() function
16
- result = classifier(user_input)[0]
17
- label = result['label']
18
- score = result['score']
19
 
20
- if label == 'POSITIVE':
21
- st.success(f'{label} sentiment (score: {score})')
22
- else:
23
- st.error(f'{label} sentiment (score: {score})')
 
 
 
 
 
 
11
  user_input = form.text_area(label = 'Enter your text', value = "I love steamlit and hugging face!")
12
  submit = form.form_submit_button('Submit')
13
 
14
+ model_name = "distilbert-base-uncased-finetuned-sst-2-english"
15
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
16
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
17
+
18
+ test = [user_input]
19
 
20
+ if submit:
21
+ classifier = pipeline("sentiment-analysis", model = model_name) #using the pipeline() function
22
+ batch = tokenizer(test, padding = True, truncation = True, max_length = 512, return_tensors = "pt")
23
+
24
+ with torch.no_grad():
25
+ outputs = model(**batch, labels = torch.tensor([1, 0]))
26
+ st.write(outputs)
27
+ predictions = F.softmax(outputs.logits, dim = 1)
28
+ st.write(predictions)