-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
616de9f
commit c316114
Showing
2 changed files
with
136 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,23 @@ | ||
import streamlit as st | ||
import random | ||
import time | ||
from fastai.text.all import * | ||
|
||
# from fastai.text.all import * | ||
|
||
# @st.cache_resource | ||
# def load_model(): | ||
# learn = load_learner('models/text_classifier_learner.pkl') | ||
# return learn | ||
|
||
# learn = load_model() | ||
|
||
classes = ["Kitaifa", "Biashara", "Kimataifa"] | ||
@st.cache_resource | ||
def load_model(): | ||
with st.spinner('Model is being loaded...'): | ||
learn = load_learner('models/text_classifier_model.pkl') | ||
return learn | ||
|
||
st.title('ULMFiT Swahili News Article Classifier') | ||
|
||
st.markdown(""" | ||
ULMFiT (Universal Language Model Fine-tuning) is an effective transfer learning method for NLP tasks. | ||
""") | ||
|
||
def run_spinner(): | ||
with st.spinner('Model is being loaded . . .'): | ||
time.sleep(15) | ||
|
||
run_spinner() | ||
|
||
user_text = st.text_area('Enter text for classification') | ||
|
||
if st.button('Classify'): | ||
if user_text: | ||
if len(user_text) > 200: | ||
time.sleep(3) | ||
pred_class = random.choice(classes) | ||
st.write(f"Input text belongs to: {pred_class}") | ||
else: | ||
st.write("Text too short. Please enter text with more than 200 characters.") | ||
pred_class, pred_idx, outputs = learn.predict(user_text) | ||
st.write(f"Input text belongs to: {pred_class}") | ||
else: | ||
st.write("Please enter text to classify.") |