File size: 1,130 Bytes
f5e88ed |
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 |
import streamlit as st
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
import torch
st.title("Multi classification Fine tunning model")
# Load model and tokenizer
model_dir = "distilbert_fine_tuned_model"
tokenizer = DistilBertTokenizer.from_pretrained(model_dir)
model = DistilBertForSequenceClassification.from_pretrained(model_dir)
def predict_class(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
outputs = model(**inputs)
prediction_value = torch.argmax(outputs.logits, dim=1).item()
stars=[" 1 stars"," 2 stars"," 3 stars"," 4 stars"," 5 stars"]
st.write(stars[prediction_value])
inputs_text=st.text_input("Please enter the text",value="I think I really like this place. Ayesha and I had a chance to visit Cheuvront on a Monday night. It wasn\'t terribly busy when we arrived and we were warmly greeted. Unfortunately we were seated next to a loud group of young children that thought they knew something of the world ")
if st.button("submit"):
predict_class(inputs_text)
|