File size: 1,128 Bytes
2573b43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Initialize the zero-shot classification pipeline
@st.cache_resource
def load_classifier():
    return pipeline("zero-shot-classification", model="facebook/bart-large-mnli")

classifier = load_classifier()

# Streamlit app interface
st.title("Webpage Subject Classifier")
st.write(
    """
    Enter the text content of a webpage below to classify it into one of the following subjects:
    - Mathematics
    - Language Arts
    - Social Studies
    - Science
    """
)

# Text input area
text_input = st.text_area("Paste the webpage content here:", height=200)

# Define the candidate labels
labels = ["Mathematics", "Language Arts", "Social Studies", "Science"]

# Perform classification when the "Classify" button is clicked
if st.button("Classify"):
    if text_input.strip():
        with st.spinner("Classifying..."):
            result = classifier(text_input, labels)
            predicted_label = result["labels"][0]
            st.success(f"The predicted subject is: **{predicted_label}**")
    else:
        st.warning("Please enter some text to classify.")