Spaces:
Runtime error
Runtime error
File size: 1,324 Bytes
741ea16 4a2ff38 741ea16 4a2ff38 a7cd630 4a2ff38 a7cd630 4a2ff38 a7cd630 4a2ff38 741ea16 4a2ff38 741ea16 4a2ff38 609af6d 4a2ff38 741ea16 4a2ff38 7e9aed2 b6f1866 4c26a9c 8b7655d |
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 37 38 39 40 |
import streamlit as st
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
# Load the model and tokenizer from Hugging Face
model_name = "KevSun/Personality_LM"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Streamlit app
st.title("Personality Prediction App")
st.write("Enter your text below to predict BigFive Personality traits:")
# Input text from user
user_input = st.text_area("Your text here:")
if st.button("Predict"):
if user_input:
# Tokenize input text
inputs = tokenizer(user_input, return_tensors="pt")
# Get predictions from the model
with torch.no_grad():
outputs = model(**inputs)
# Extract the predictions
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predictions = predictions[0].tolist()
# Display the predictions
labels = ["agreeableness", "openness", "conscientiousness", "extraversion", "neuroticism"]
for label, score in zip(labels, predictions):
st.write(f"{label}: {score:.4f}")
else:
st.write("Please enter your text.")
#st.info("Note: This is a demonstration and predictions may not be entirely accurate.")
|