import streamlit as st from transformers import pipeline import groq # Initialize Groq API groq_client = groq.Client() # Initialize the zero-shot classification pipeline from Hugging Face classifier = pipeline("zero-shot-classification", model="joeddav/xlm-roberta-large-xnli") # Function to perform zero-shot classification def classify_text(sequence, candidate_labels): result = classifier(sequence, candidate_labels) return result # Streamlit UI elements st.title("Zero-Shot Text Classification with XLM-RoBERTa") st.markdown("Enter a text and select candidate labels for classification.") # Text input from the user sequence = st.text_area("Enter text to classify", "", height=150) # Candidate labels candidate_labels = st.text_input("Enter candidate labels (comma separated)", "politics, health, education") candidate_labels = [label.strip() for label in candidate_labels.split(",")] # When the classify button is pressed if st.button("Classify Text"): if sequence: result = classify_text(sequence, candidate_labels) st.write("Classification Results:") st.write(f"Labels: {result['labels']}") st.write(f"Scores: {result['scores']}") else: st.error("Please enter text to classify.")