Spaces:
Build error
Build error
File size: 981 Bytes
5fbb974 |
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 |
import streamlit as st
from transformers import pipeline
import json
# Load the text classification model from Hugging Face
@st.cache_resource
def load_model():
model_name = "annyalvarez/MoralS-BERT"
return pipeline("text-classification", model=model_name)
model = load_model()
# Streamlit app interface
st.title("Moral Values Text Classification")
# Text input from the user
user_input = st.text_area("Enter text for classification:", "")
if st.button("Classify"):
if user_input:
# Get model predictions
predictions = model(user_input)
# Sort predictions by score
predictions = sorted(predictions, key=lambda x: x['score'], reverse=True)
# Format the predictions as required
output = [{
"label": pred['label'],
"score": pred['score']
} for pred in predictions]
# Display the output
st.json(output)
else:
st.write("Please enter some text to classify.")
|