subject / app.py
pleonova's picture
Create app.py
2573b43 verified
raw
history blame
1.13 kB
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.")