Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
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)
|