|
import streamlit as st
|
|
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
|
import torch
|
|
|
|
st.title("Multi classification Fine tunning model")
|
|
|
|
|
|
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)
|
|
|