Build AI Chatbot in 5 Minutes with Hugging Face and Gradio – KDnuggets

Learn to create a Gradio chatbot using low code techniques directly in your browser with this easy-to-follow tutorial.

Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image by Author

 
This short tutorial will build a simple chatbot using the Microsoft DialoGPT model, Hugging Face Space, and Gradio interference. You will be able to develop and customize your own app in 5 minutes using a similar technique. 
 
 
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from Space

 
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from AI ChatBot

 
 
We will click on the “Files” tab > + Add file > Create a new file.  
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from kingabzpro/AI-ChatBot

 
Create a Gradio interface. You can copy my code. 
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from app.py

 
I have loaded the “microsoft/DialoGPT-large” tokenizer and model and created a `predict` function for getting the response and creating the history.  
 
Moreover, I have provided my app with a customized theme: boxy_violet. You can browse Gradio Theme Gallery to select the theme according to your taste. 
 
 
Now, we need to create a `requirement.txt` file and add the required Python packages. 
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from requirements.txt

 
 
After that, your app will start building, and within a few minutes, it will download the model and load the model inference.
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio

 
 
The Gradio App looks awesome. We just have to create a `predict` function for every different model architect to get responses and maintain history.
You can now chat and interact with an app on kingabzpro/AI-ChatBot or embed your app on your website using https://kingabzpro-ai-chatbot.hf.space.
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from kingabzpro/AI-ChatBot

 
Are you still confused? Look for hundreds of chatbot apps on Spaces to get inspiration and understand the model inference.
For example, if you have a mode that is finetuned on “LLaMA-7B”. Search for the model and scroll down to see various implementations of the model. 
 
Build AI Chatbot in 5 Minutes with Hugging Face and Gradio
Image from decapoda-research/llama-7b-hf

 
 
In conclusion, this blog provides a quick and easy tutorial on creating an AI chatbot using Hugging Face and Gradio in just 5 minutes. With step-by-step instructions and customizable options, anyone can easily create their chatbot.
It was fun, and I hope you have learned something. Please share your Gradio demo in the comment section. If you are looking for an even simpler solution, check out OpenChat: The Free & Simple Platform for Building Custom Chatbots in Minutes.
 
 
Abid Ali Awan (@1abidaliawan) is a certified data scientist professional who loves building machine learning models. Currently, he is focusing on content creation and writing technical blogs on machine learning and data science technologies. Abid holds a Master’s degree in Technology Management and a bachelor’s degree in Telecommunication Engineering. His vision is to build an AI product using a graph neural network for students struggling with mental illness.
 
Get the FREE ebook ‘The Great Big Natural Language Processing Primer’ and the leading newsletter on AI, Data Science, and Machine Learning, straight to your inbox.
By subscribing you accept KDnuggets Privacy Policy
Get the FREE ebook ‘The Great Big Natural Language Processing Primer’ and the leading newsletter on AI, Data Science, and Machine Learning, straight to your inbox.
By subscribing you accept KDnuggets Privacy Policy
Subscribe To Our Newsletter
(Get The Complete Collection of Data Science Cheat Sheets)
Get the FREE ebook ‘The Great Big Natural Language Processing Primer’ and the leading newsletter on AI, Data Science, and Machine Learning, straight to your inbox.
By subscribing you accept KDnuggets Privacy Policy
Get the FREE ebook ‘The Complete Collection of Data Science Cheat Sheets’ and the leading newsletter on Data Science, Machine Learning, Analytics & AI straight to your inbox.
By subscribing you accept KDnuggets Privacy Policy

source

Jesse
https://playwithchatgtp.com