File size: 1,250 Bytes
b77a775
2c19e76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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.")