Spaces:
Running
Running
File size: 1,031 Bytes
b23dced 1b6a720 b23dced 1b6a720 b23dced 3a15f10 b23dced 0dc667c b23dced 0dc667c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import streamlit as st
import torch
import torch.nn.functional as F
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForSequenceClassification
st.title('Can I Patent This?')
# steamlit form
form = st.form(key='sentiment-form')
user_input = form.text_area(label = 'Enter your text', value = "I love steamlit and hugging face!")
submit = form.form_submit_button('Submit')
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
test = [user_input]
if submit:
classifier = pipeline("sentiment-analysis", model = model_name) #using the pipeline() function
batch = tokenizer(test, padding = True, truncation = True, max_length = 512, return_tensors = "pt")
with torch.no_grad():
outputs = model(**batch, labels = torch.tensor([1, 0]))
st.write(outputs)
predictions = F.softmax(outputs.logits, dim = 1)
st.write(predictions)
|