Skip to content

Commit

Permalink
streamlit app
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKalema committed Jun 11, 2024
1 parent 9b106a3 commit d3d3a87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
36 changes: 22 additions & 14 deletions app.py
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.")
3 changes: 0 additions & 3 deletions models/text_classifier_learner.pth

This file was deleted.

0 comments on commit d3d3a87

Please sign in to comment.