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.")