Toxicity Classifier Streamlit App

AI Anytime · Beginner ·📐 ML Fundamentals ·3y ago

Key Takeaways

The video demonstrates how to create a toxicity classifier app using Python, Streamlit, and a trained machine learning model with TF-IDF to classify text as toxic or non-toxic.

Full Transcript

hello everyone welcome to AI anytime channel so in previous video we created an endpoint of the toxicity classifier model that we created using supervised machine learning algorithms so we created this endpoint in fast API and we tested that API it was working completely fine so what we will do in this video is that we'll create a very simple streamlit application okay we'll take that model and we'll try to integrate and we'll have an UI where there will be an input text area and then we will give our text and in it will then detect or classify whether the text is toxic or non-toxic and once we build this application we'll also deploy this on share streamlit okay through GitHub so if you see currently I'm on my GitHub uh repository toxicity classifier app if you haven't uh downloaded this notebook or the API endpoint you can download it from here and you can test it out so now what we are going to do okay let me go back to my vs code you can see I'm on my vs code just give me a minute and yeah so you can see this this was our API dot Pi file where we created the endpoint you can see with our endpoint was predict and we what we did we we have loaded our model here okay and once we have this model and TF IDF we created this endpoint called predict and then you know we uh ran that model and got the response okay now what we will do here guys will create an app so I'm calling it app.pi and here we'll use streamlit which is a web framework you know to uh create powerful data science application okay it's it's very easy for you know the developers who have very limited knowledge of web Technologies okay okay so if you see uh on requirement.txt I have added streamlit Library we have to install it as well I have already installed it so I'm not going to install what I'm going to do now I'm going to just import streamlit add HD and rest will be same so I'm just going to take a code snippet from here and what I will do I'll just use this here so what am I doing here we have extremely it as St we are also importing pickle to load the model and TF IDF features and then we have numpy for mathematical operations and then we have psychic learn packages you know to run and do the processing of you know feature extraction and other things right so now what we have to do here let's create some functions okay so what we will do first function will be you know to PF IDF this is going to be our first function I'll just take the code from here so what I'm going to do take this code let's call it load TF IDF load TF IDF and then I will just pass this here and I'll just return this return PF IDF and the next is to load the model so I'll say load model it will be again like same so we'll have uh let's take the model code from here NB model and let me just copy and paste MB model looks fine and we'll just return this NB model so now we have created two functions one is for loading the TF IDF here you can see we have saved here right with pickle and the other is the nav based model OKAY the toxicity model the next thing is let's write the function for toxicity as well so toxicity detection and here we will pass a text as an input and then we'll predict the first thing is to load the TF idea because we have to do the transform we have to use the transform function right so TF IDF and we'll use load TF IDF so this is the variable where we are using this function right we are loading it so load TF IDF now the next is we'll use this transform so you can see let me just write over here you can see now we are uh using the transform we are applying the transform function on this text which is an input parameter and then we are converting it to an array so to array and once we have this text T of IDM now we have to load the model as well so model and then here we'll have load model so here we are storing our model guys okay so model and then we'll do couple of these lines let's copy and predict so you can see the prediction it will not be n b model here because our variable has been changed to model now so model dot predict and then we have text DF idea variable we are passing it over here to not get the prediction that's what we are doing map the predicted class twisting I think that is this is good so now what we can do we can just say return class name this is what we are returning okay so this is the function that we have created so now we have three different functions here the first where we are loading the TF IDF the second we are returning the nav based model and the third for the toxicity detection where input parameter is text and we are doing all our operations on these functions okay and now in we have the class name the result now what we will do we'll create an estimate application and in that let's first do St Dot header I'm calling it toxicity you know detection app this is going to be this HD dot header toxicity detection app now let's also use a server header kind of a step you know just to let end user enter the text below into the text below and now what we have to do hd.serve header uh enter the text below now what will do HD Dot let's call it text input St dot text input and here we'll have entered your text enter your text now this is the text input that we have HD dot header hd.sub header and text input SE dot texture now what we will do we'll use this function on this texture right so now let's say call it a result so result equals uh text uh what we're going to do now guys that we have to load this toxicity reduction we are not going to fast text which will be text input we have to pass this variable yet which is storing our input text let's do one thing let's do not do that okay so what we can do we can say if text input let's first check if there is a value also or not is not none and then we create a estimate button we call it SD dot button so that will be if HD dot button and let's call this button analyze analyze and this result you can see this is another result and now what we can do uh result let's call it HD dot sub header detected result is below something like this and we can do HD dot info we can use the status messages uh we have several status message option in streamlit being info success warnings you know there there are an error as well so we'll use H dot info because this is a kind of info that we are you know presenting on the UI saying XT dot info what we can do guys we can just write the result is and we can do this plus and that will be our result guys so result and okay excuse me this is going to be the hd.info HD dot info is done sub header result now let's run this guy and see if we are able to get the desired response so what we did we first imported these libraries streamlit for the web UI and then pickle for loading the models and the TF IDF then we have numpy and Cyclone packages then we created two functions you know to load the TF IDF and the model and then we created one more function called toxicity detection where we have written our code for toxicity detection using these functions and then we created a streamlined snippet where we have headers operators and input text area where the end user will give the input text and then we'll run the model on top of that input text so let's now run this so how we run an estimate application is like we do streamlit run my file name is app.pi so you can see this is the application that we have is a toxicity detection app enter the text below enter your text now in this I'll just say I'll just use a toxic okay what did it right there such a so I'm just using this uh statement here such a f word you are right and let's analyze so you can see the detected result is below with the result is toxic okay the result is toxic for this now let's try something else the product or the product was you know fantastic and I really liked it and suppose this is my review right and I want to just find it out if this review you know done by the end user is toxic or non-toxic so you can see the result is non-toxic in this case right so now let's do one thing okay what we'll do if you come back here on vs code you'll see that you know we have created this estimate application and use the same kind of you know found here on this GitHub repository toxicity classifier app and you know in the next video we'll deploy this okay on share extremely okay this that you see that app.pi okay so this streamlit application the toxicity detection app you know we will deploy this application on shared streamlit through GitHub okay so they kind of provide the space like you know around 1GB where you cannot deploy your application stimulate application in free so in today's video uh just to summarize we created a toxicity detection app that takes your input text and then classify classifies that between toxic and non-toxic so if you like this video guys please like this video and uh subscribe the channel if you have not subscribed yet and please share the video and Channel with your friends and to peer okay thanks for watching the videos guys see you in the next video

Original Description

In this video, we explore how to create a toxicity classifier app using Python and Streamlit. The app utilizes a trained machine learning model and TF-IDF (Term Frequency-Inverse Document Frequency) to classify text as either toxic or non-toxic. Whether you're a seasoned programmer or just starting out, this tutorial will show you how to build a fun and interactive application that can help in detecting toxic comments on the internet. So, grab your Python development environment and let's get started! GitHub Link: https://github.com/AIAnytime/Toxicity-Classifier-App Streamlit Documentation: https://docs.streamlit.io/ #python #streamlit #ai #nlp #datascience #tech #technology
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from AI Anytime · AI Anytime · 13 of 60

1 Spelling and Grammar Checking Streamlit App: Building Docker Image
Spelling and Grammar Checking Streamlit App: Building Docker Image
AI Anytime
2 Spelling and Grammar Checking Streamlit App: Docker Image and Docker Hub
Spelling and Grammar Checking Streamlit App: Docker Image and Docker Hub
AI Anytime
3 Image Caption Generator: Google Colab and Hugging Face
Image Caption Generator: Google Colab and Hugging Face
AI Anytime
4 Low Code/No Code AI Platform Teachable Machine: Brain MRI Image Classification
Low Code/No Code AI Platform Teachable Machine: Brain MRI Image Classification
AI Anytime
5 Low Code/No Code AI Platform Teachable Machine: Testing the Model
Low Code/No Code AI Platform Teachable Machine: Testing the Model
AI Anytime
6 Low Code/No Code AI Platform: Streamlit App for Brain MRI Image Classification
Low Code/No Code AI Platform: Streamlit App for Brain MRI Image Classification
AI Anytime
7 Readme Generator Streamlit App using ChatGPT
Readme Generator Streamlit App using ChatGPT
AI Anytime
8 Generate Minutes of Meeting (MoM) from Video using ChatGPT: AI as an API
Generate Minutes of Meeting (MoM) from Video using ChatGPT: AI as an API
AI Anytime
9 The Great AI Showdown: ChatGPT vs ChatSonic 🔥
The Great AI Showdown: ChatGPT vs ChatSonic 🔥
AI Anytime
10 Generating Transcripts and News Article with Whisper, GPT-3.5, ChatGPT and Streamlit
Generating Transcripts and News Article with Whisper, GPT-3.5, ChatGPT and Streamlit
AI Anytime
11 Toxicity Classifier using Machine Learning and NLP
Toxicity Classifier using Machine Learning and NLP
AI Anytime
12 Toxicity Classifier API using FastAPI
Toxicity Classifier API using FastAPI
AI Anytime
Toxicity Classifier Streamlit App
Toxicity Classifier Streamlit App
AI Anytime
14 Low-Code Insurance Prediction with PyCaret and Streamlit
Low-Code Insurance Prediction with PyCaret and Streamlit
AI Anytime
15 Deploy Streamlit Python Application for Free
Deploy Streamlit Python Application for Free
AI Anytime
16 GPT3 Powered Text Analytics App
GPT3 Powered Text Analytics App
AI Anytime
17 AI Image Generation Streamlit App
AI Image Generation Streamlit App
AI Anytime
18 Streamlit and txtai: Building an Abstractive Summarization App in Python
Streamlit and txtai: Building an Abstractive Summarization App in Python
AI Anytime
19 Building a Topic Modeling and Labeling app with Streamlit
Building a Topic Modeling and Labeling app with Streamlit
AI Anytime
20 The Art of AI: Exploring Midjourney, Dall-E, and Lexica
The Art of AI: Exploring Midjourney, Dall-E, and Lexica
AI Anytime
21 Exploring the latest Large Language Models (LLaMA and Alpaca)
Exploring the latest Large Language Models (LLaMA and Alpaca)
AI Anytime
22 Comparing LLMs like GPT-X, LLaMA, and Alpaca: Analyzing the Perplexity Score
Comparing LLMs like GPT-X, LLaMA, and Alpaca: Analyzing the Perplexity Score
AI Anytime
23 GPT-3 powered Q&A App using Langchain, GPT-Index, and Gradio
GPT-3 powered Q&A App using Langchain, GPT-Index, and Gradio
AI Anytime
24 All things #ai . Latest and greatest in AI. #tech #python #chatgpt #youtubeshorts #shorts #gpt3
All things #ai . Latest and greatest in AI. #tech #python #chatgpt #youtubeshorts #shorts #gpt3
AI Anytime
25 Text-to-Video Generation using a Generative AI Model
Text-to-Video Generation using a Generative AI Model
AI Anytime
26 #ai brand name generator. #artificialintelligence #tech #shorts #youtubeshorts #youtube #chatgpt
#ai brand name generator. #artificialintelligence #tech #shorts #youtubeshorts #youtube #chatgpt
AI Anytime
27 Talking AGI with Sam Altman: A Deepfake Showcase
Talking AGI with Sam Altman: A Deepfake Showcase
AI Anytime
28 A conversation with ChatGPT creator Sam Altman. #tech #technology #ai #shorts #viral
A conversation with ChatGPT creator Sam Altman. #tech #technology #ai #shorts #viral
AI Anytime
29 Get to Know Anthropic's Claude: The Ultimate ChatGPT Competitor
Get to Know Anthropic's Claude: The Ultimate ChatGPT Competitor
AI Anytime
30 #shorts #chatgpt #python #datascience #tech #coding
#shorts #chatgpt #python #datascience #tech #coding
AI Anytime
31 Recipe Generator App from Cooking Videos using Whisper and ChatGPT
Recipe Generator App from Cooking Videos using Whisper and ChatGPT
AI Anytime
32 Segment Anything Model by Meta AI: An Image Segmentation Model
Segment Anything Model by Meta AI: An Image Segmentation Model
AI Anytime
33 One of the best #ai #books based on #tensorflow. #tech #coding #shorts #chatgpt #machinelearning
One of the best #ai #books based on #tensorflow. #tech #coding #shorts #chatgpt #machinelearning
AI Anytime
34 Music Generation using Mubert #ai . #music #shorts #youtubeshorts #chatgpt #generativeai
Music Generation using Mubert #ai . #music #shorts #youtubeshorts #chatgpt #generativeai
AI Anytime
35 Image to Text Prompt: Reverse Engineering AI Image Generation
Image to Text Prompt: Reverse Engineering AI Image Generation
AI Anytime
36 Image Generation for #ramadan using #ai. #midjourney #chatgpt #shorts #youtubeshorts #islam
Image Generation for #ramadan using #ai. #midjourney #chatgpt #shorts #youtubeshorts #islam
AI Anytime
37 How to build an AI-ready organization: Cultivating a Data-Driven Culture
How to build an AI-ready organization: Cultivating a Data-Driven Culture
AI Anytime
38 Midjourney: Generate AI-powered Images
Midjourney: Generate AI-powered Images
AI Anytime
39 Getting Started with Graphs: A Beginner's Guide (Part 1 of GNN Series)
Getting Started with Graphs: A Beginner's Guide (Part 1 of GNN Series)
AI Anytime
40 Build India's First ChatGPT like App for Politics: BJP-GPT
Build India's First ChatGPT like App for Politics: BJP-GPT
AI Anytime
41 Meet BJP-GPT.... @AIAnytime  #bjp #news #shorts #tech #chatgpt #ai #youtubeshorts #coding #video
Meet BJP-GPT.... @AIAnytime #bjp #news #shorts #tech #chatgpt #ai #youtubeshorts #coding #video
AI Anytime
42 ChatPDF... #chatgpt  for PDF files. #ai #generativeai #shorts #youtubeshorts #coding #tech #ai
ChatPDF... #chatgpt for PDF files. #ai #generativeai #shorts #youtubeshorts #coding #tech #ai
AI Anytime
43 Free AI Image Generation #ai #chatgpt #coding #tech #shorts #youtubeshorts #shortvideo #generativeai
Free AI Image Generation #ai #chatgpt #coding #tech #shorts #youtubeshorts #shortvideo #generativeai
AI Anytime
44 Transform old photos into Vibrant Memories with Deoldify AI: Build a Streamlit App
Transform old photos into Vibrant Memories with Deoldify AI: Build a Streamlit App
AI Anytime
45 Open Assistant: The Real Open-sourced LLM
Open Assistant: The Real Open-sourced LLM
AI Anytime
46 Thanks to @YannicKilcherand team for the open sourced LLM Open Assistant. #ai #shorts #tech
Thanks to @YannicKilcherand team for the open sourced LLM Open Assistant. #ai #shorts #tech
AI Anytime
47 Search Engine for AI generated images. #ai #tech #technology #generativeai #chatgpt  #shorts #video
Search Engine for AI generated images. #ai #tech #technology #generativeai #chatgpt #shorts #video
AI Anytime
48 Generative AI Video Platform "Synthesia" #shorts #youtubeshorts #ai #tech #chatgpt #generativeai
Generative AI Video Platform "Synthesia" #shorts #youtubeshorts #ai #tech #chatgpt #generativeai
AI Anytime
49 Text to speech Voice AI platform. #shorts #youtubeshorts #ai #tech #technology #python #coding
Text to speech Voice AI platform. #shorts #youtubeshorts #ai #tech #technology #python #coding
AI Anytime
50 Create Amazing Videos with ChatGPT and Pictory: Free AI-powered Video Creation
Create Amazing Videos with ChatGPT and Pictory: Free AI-powered Video Creation
AI Anytime
51 Want to create beautiful video using #chatgpt and #pictory ? Watch the tutorial on channel. #ai
Want to create beautiful video using #chatgpt and #pictory ? Watch the tutorial on channel. #ai
AI Anytime
52 Animate your photos using AI. Bring old family photos to life. #ai #tech #shorts #shortvideo #coding
Animate your photos using AI. Bring old family photos to life. #ai #tech #shorts #shortvideo #coding
AI Anytime
53 Create a PDF Search and Summarization Tool in less than 100 Lines of Code: GPT-Index and Streamlit
Create a PDF Search and Summarization Tool in less than 100 Lines of Code: GPT-Index and Streamlit
AI Anytime
54 Text to Video Generation using Videocrafter: Intuitive Math behind Latent Diffusion Model
Text to Video Generation using Videocrafter: Intuitive Math behind Latent Diffusion Model
AI Anytime
55 Gamma AI: Create presentation PPT easily with #ai . #chatgpt #shorts #shortvideo #tech #coding
Gamma AI: Create presentation PPT easily with #ai . #chatgpt #shorts #shortvideo #tech #coding
AI Anytime
56 Tripnotes: Free AI tools for your trip planning. #ai #chatgpt #shorts #youtubeshorts #video
Tripnotes: Free AI tools for your trip planning. #ai #chatgpt #shorts #youtubeshorts #video
AI Anytime
57 Meet Bark (New Text to Speech Model): Clone Any Voice to Generate Music and Speech
Meet Bark (New Text to Speech Model): Clone Any Voice to Generate Music and Speech
AI Anytime
58 Fliki: The free AI video creation tool. #ai #shorts #shortvideo #youtubeshorts #chatgpt #tech #news
Fliki: The free AI video creation tool. #ai #shorts #shortvideo #youtubeshorts #chatgpt #tech #news
AI Anytime
59 Ask Anything Tool: Chat with Your Video using ChatGPT, MiniGPT4, and StableLM
Ask Anything Tool: Chat with Your Video using ChatGPT, MiniGPT4, and StableLM
AI Anytime
60 HuggingChat: Open Source ChatGPT (Interface and Model)
HuggingChat: Open Source ChatGPT (Interface and Model)
AI Anytime

This video tutorial guides viewers in creating a toxicity classifier app using Python and Streamlit, leveraging a trained machine learning model and TF-IDF for text classification. The app can be used to detect toxic comments on the internet. By following this tutorial, viewers can gain hands-on experience in building a fun and interactive application.

Key Takeaways
  1. Install required libraries including Streamlit and scikit-learn
  2. Import necessary libraries and load the trained machine learning model
  3. Preprocess text data using TF-IDF
  4. Create a Streamlit app to classify text as toxic or non-toxic
  5. Deploy the app and test its functionality
💡 The use of TF-IDF for text preprocessing can significantly improve the accuracy of text classification models.

Related Reads

Up next
Dropout in Deep Learning
AnuTech-CH
Watch →