import subprocess import sys def install(package): subprocess.check_call([sys.executable, "-m", "pip", "install", package]) install("tensorflow") install("numpy") install("transformers") import transformers from transformers import DistilBertTokenizer from transformers import TFDistilBertForSequenceClassification import streamlit as st import numpy as np import tensorflow as tf x = st.header("Welcome to the STEM NLP application!") model = TFDistilBertForSequenceClassification.from_pretrained("kaixinwang/NLP") MODEL_NAME_1 = 'distilbert-base-uncased' tokenizer = DistilBertTokenizer.from_pretrained(MODEL_NAME_1) x = st.text_input("Type in your review here:") st.write("Your review is:", x) encoding = tokenizer(x, truncation=True, padding=True) encoded = tf.data.Dataset.from_tensor_slices((dict(encoding), np.ones(1))) preds = model.predict(encoded.batch(1)).logits prob = tf.nn.softmax(preds, axis=1).numpy() prob_max = np.argmax(prob, axis=1) st.write("Sentiment:", prob_max, "Score:", prob[prob_max]) # x = st.slider('Select a value') # st.write(x, 'squared is', x * x)