|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
@st.cache_resource |
|
def load_classifier(): |
|
return pipeline("zero-shot-classification", model="facebook/bart-large-mnli") |
|
|
|
classifier = load_classifier() |
|
|
|
|
|
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 = st.text_area("Paste the webpage content here:", height=200) |
|
|
|
|
|
labels = ["Mathematics", "Language Arts", "Social Studies", "Science"] |
|
|
|
|
|
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.") |
|
|