File size: 1,272 Bytes
df86432
 
 
 
8979155
 
 
df86432
 
8979155
 
df86432
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
import streamlit as st
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

# Paths to the saved model and tokenizer
model_path = "path_to_save_model"
tokenizer_path = "path_to_save_tokenizer"

# Load the model and tokenizer from the Hugging Face Hub
model = AutoModelForSequenceClassification.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)

# Function to predict the sentiment
def predict_sentiment(text):
    inputs = tokenizer(text, return_tensors="pt")
    with torch.no_grad():
        outputs = model(**inputs)
    probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
    return torch.argmax(probs, dim=-1).item(), probs

# Streamlit interface
st.title("KIWI Classifier")
st.write("Enter a question or statement to classify:")

user_input = st.text_area("Your input", "")
if st.button("Classify"):
    if user_input:
        label, probabilities = predict_sentiment(user_input)
        st.write(f"Prediction: {label}")
        st.write(f"Probabilities: {probabilities.tolist()}")
    else:
        st.write("Please enter some text to classify.")

# Additional instructions or information
st.write("This application uses a fine-tuned BERT model to classify questions and statements.")