Hugging Face + Langchain in 5 mins | Access 200k+ FREE AI models for your AI apps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you are building AI apps you have to learn how to use hugging face it is one of the top AI companies valued more than 2 billion dollars it has more than 16 000 followers on GitHub its product is used by Google Amazon Microsoft and meta with more than 200 000 different type of AI models including image to text text to speech below text to image and many more that's why if you are building AI apps you absolutely need to learn how to use it and I'm going to show you how can you use hugging face platform and build it with other Public Library like launching let's get to it in the show hugging face is a place for you to discover and share AI models so there are three parts of the hugging phase platform models datasets and space firstly is models this place where you can find all different sorts of models to use for example if we are interested in using image text I can select the category on the left and then on the right side it choose any of the popular image to text model and once I get into this page I on the left side they will have some description about model and on the right side it allows you to preview and test the AI model directly on their hosted version and this is why Hackney face is so useful so without it you will need to find the models download it to your local machine or host somewhere and then try to run it to know if it is the right model for you but with hugging face they are hosting on their own machine and you can test it immediately but for this image to text model I can drag and drop image directly and see what kind of results it will get if and want to use it it allows you to easily deploy this model on different servers you can also use host API on hugging face hub for free it is a bit slow and they have rate limits but it's definitely enough for you to run some tests but on the other hand if you prefer to run the models locally on your own machine you can also use their Transformers library and I will talk about how do we do that very soon the listen model on the outside they also have data sets and this is where you can find a lot of data sets that you can use to train your own model for example if I want to build my own voice model I can filter down to text to speech and find a specific language that I want to use then you can click on any of them and preview what are the data sets they have unless you are training your own model you probably won't use this data sets too much and the last part is space space is initially designed for people to Showcase and share the AI apps that they build so they allow you to deploy the apps that you have been building very easily on their own machine and they provide free version too but on the other side you can explore what other AI apps that people are building and there are a lot of very cool stuff you can just click on them and start playing with those apps and you can also learn how do they build those things clicking on this button it will show you all the models are used to build these apps and you can click on the files to say the source code how are we going to use those models on hugging face while we are implementing Inland chain I'll take you through a step-by-step example of implementing such AI app where I can upload the image and then it can automatically turn it into an audio story the man and woman sat on the couch lost in silence he broke it I love you she smiled and said I know as through this example you will learn how to use a few different hugging face AI models let's get to it firstly let's think step by step how we're going to implement this this app will have three components where first they need an image to text model to let the machine understand what is the scenario based on the photo and then we will use large language model to generate a short story and in the end we'll use a text to speech model to generate the audio story and to find the right image to text model we can go to hugging face and filter down the image text models the one I will be using is the one called blip you will need to create a hugging face account and then go to settings access tokens and create an access token for land chain let's go back to the visual studio and create a DOT NV file where we restore all the credentials an output hugging face Hub API token once I save that let's import a few libraries we'll reverse the import.env and run this to be able to access hugging face API token that we store in the EMV file and then we will import pipelines from Transformers so pipeline will allow us to download the hugging phase model into our local machine and now we're ready to implement the first one image into text model we've created pipeline to load the AI model firstly we were putting the task here which is image of the text some of you might be curious where do we get this task name image to text from so hugging phase Transformers Library actually have a predefined list of tasks and you can go to this URL huggingface.com tasks to understand what are the tasks that it supports and you can click on any of them to get a more detailed tutorial about how to use that specific tasks and then we need to put the model name you can get a model Name by clicking on this using Transformers and just copy paste this one and we will run image to text pass on the URL of the image file then we're going to print it in our copy paste a photo in the root folder for the testing purpose now let's see what results we got we run python app.py now gather these results a group of people standing on a boat which is very accurate description and I only want to return the actual text here so I will do choose the library of the first item and generated tax and next is that we want to use a large language model to generate a short story based on this scenario that we got from the image you can use some open source model hugging face as well but for me I do prefer use GPT so use launching here so that's adding the open AI API key here as well and then let's import a few libraries from Land chain and this is a function we're going to run we will firstly create a prompt template that lets GPT to generate story and then we'll create this lrm chain with GPD 3.5 turbo let's try and now all we need to do is just turn those tags into a speech using a text to speech model and again we will do the same thing go to the models page find text-to-speech models and find the most popular one but this time I want to share another way you can use hugging face model so you can click on this deploy button and there should be option called info difference API and this is super easy and fast way for you to test out the honeyface API for free so this is what we're gonna do we're gonna use this ring request Library going back here import requests and then create a function text to speech and at the top I'm going to load the hugging face API token so that I can pass on to the API request and I were adding the API URL here putting the header that passed on my hugging face API token and then create a message of inputs now just call this API requests and for the model I'm using the result it returns is a Flac file which is one type of audio file so I'm going to store it locally let's try it oh sorry I forgot to add the OS Library which allow us to get the API token and let me try again okay here we go we got this audio file generated the group of people were standing on the boat their eyes fixed on the horizon the sample setting painting the sky with brilliant shades of pink pink and orange okay now you can see whole thing has been working all we need to do now just connecting everything together and give the UI a layer with streamlit so our import streamlit as ST which is the library that allow us create a user interface for python code and button I will add this and also create a main function which will be called when the app is loaded so first I will reset the page title and then it will give header turn image into audio story I will put a uploaded file equal to St dot file uploader this will allow people to upload a image file then if the file is uploaded I will firstly try to save this image and display the image by sd.image then I will call in the function that we created get the model to generate text from the image we uploaded and then let GPT generate a story based on the scenario in the end our general audio file from the stories and we're going to display scenario and stories in here and in the end we're gonna display the audio file that we got and that's pretty much it let's try to run this app by doing streamlit round app.p1 okay so here we can upload the image and we can see it is running here if we open the terminal we should be able to see what it's doing now okay here you go you can see we already generate scenario and little story here if you click this play button it should play the audio file as they said together on the couch the man stared intently at the woman he had known for 40 years and every time he looked at her he felt like he was seeing her for the first time suddenly he blurted I think I love you the woman turned to him her eyes wide with surprise and then with a smile that lit up the room she said finally from that moment on they knew they were meant to be together okay I think of this pretty dope use case so this is how you can use hugging face models he quickly recap the easiest way for you to use that would be you can use inference API to use their hosted version directly on the other side you can also use pipeline to download all those models on your local machine if you want to learn more I highly recommend you go to thehf.com tasks to learn all the different type of tasks if it supports as well as different type of models it has one last thing I want to touch base on is I realized one of the low code AI chin build a platform called relevance AI they actually provide image to hacks model out of box and I can just create this image to speech app super quickly with their local UI and got it Droid app out of box in just like five minutes I do hope they can build a deep integration with hugging face where I can just grab different type of AI models directly but it's already a pretty good start so highly recommend alright hopefully you know how to use hacking face now and start building some super interesting AI apps if you found this content useful Please Subscribe or continue sharing all those AI experiments I'm doing thank you and see you next time
Info
Channel: AI Jason
Views: 102,303
Rating: undefined out of 5
Keywords: ai, langchain, hugging face tutorial, how to use hugging face, what is hugging face, how to use hugging face diffusion model, hugging face models, chatgpt, step by step, tutorial, huggingface, no code, langflow, flowise, ai models
Id: _j7JEDWuqLE
Channel Id: undefined
Length: 9min 47sec (587 seconds)
Published: Sun Jun 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.