Spaces:
Build error
Build error
File size: 1,675 Bytes
fb5fab5 11e8444 632d12b 11e8444 0a1b9b7 fb5fab5 22feff3 11e8444 6b307bf 11e8444 21fccbb 11e8444 e62eed9 6db63c0 11e8444 e62eed9 0a1b9b7 95f2cc8 0a1b9b7 95f2cc8 6b307bf 6db63c0 11e8444 81b925a 11e8444 95f2cc8 11e8444 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import warnings
warnings.filterwarnings("ignore")
import streamlit as st
import pandas as pd
import plotly.express as px
from src import *
import os
global model
global prediction
@st.cache_resource
def model_obj():
model = ModelLoader()
prediction = PredictionServices(model.Model, model.Tokenizer)
st.image(os.path.join("img","toxic.jpg"))
return prediction
prediction = model_obj()
def single_predict(text):
preds = prediction.single_predict(text)
if preds < 0.5:
st.success(f'Non Toxic Comment!!! :thumbsup:')
else:
st.error(f'Toxic Comment!!! :thumbsdown:')
prediction.plot(preds)
def batch_predict(data):
preds = prediction.batch_predict(data)
return preds.to_csv(index=False).encode('utf-8')
st.title('Toxic Comment Classifier')
st.write("This application will help to classify any comment or text in any language into 'TOXIC' or 'NON-TOXIC'")
tab1, tab2 = st.tabs(["Single Value Prediciton","Batch Prediction"])
with tab1:
st.subheader("Prediction")
with st.form("comment_form", clear_on_submit=True):
comment = st.text_area(label="Enter your comment")
button = st.form_submit_button(label="Predict")
if button:
with st.spinner('Please Wait!!! Prediction in process....'):
single_predict(comment)
with tab2:
st.subheader("Batch Prediction")
csv_file = st.file_uploader("Upload File",type=['csv'])
if csv_file is not None:
csv = batch_predict(csv_file)
st.download_button(
label="Download",
data=csv,
file_name='prediction.csv',
mime='text/csv',
)
|