-
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
9b106a3
commit d3d3a87
Showing
2 changed files
with
22 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
import streamlit as st | ||
from fastai.text.all import * | ||
import random | ||
import time | ||
|
||
# from fastai.text.all import * | ||
|
||
@st.cache_resource | ||
def load_model(): | ||
learn = load_learner('text_classifier_learner.pth') | ||
return learn | ||
# @st.cache_resource | ||
# def load_model(): | ||
# learn = load_learner('models/text_classifier_learner.pkl') | ||
# return learn | ||
|
||
# learn = load_model() | ||
|
||
learn = load_model() | ||
classes = ["Kimataifa"] | ||
|
||
# Streamlit app | ||
st.title('ULMFiT Swahili News Article Classifier') | ||
|
||
# Text input | ||
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: | ||
pred_class, pred_idx, outputs = learn.predict(user_text) | ||
st.write(f"Predicted Class: {pred_class}") | ||
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.") | ||
else: | ||
st.write("Please enter text to classify.") | ||
|
||
if __name__ == '__main__': | ||
st.run() | ||
st.write("Please enter text to classify.") |
This file was deleted.
Oops, something went wrong.