It’s a Tuesday morning. As a Transformers maintainer, I’m doing the identical thing I do most weekday mornings: Opening PyCharm, loading up the Transformers codebase and gazing lovingly on the chat template documentation while ignoring the 50 user issues I used to be pinged on that day. But this time, something feels different:
Something is… wait! Computer! Enhance!

Is that..?
Those user issues are definitely not getting responses today. Let’s talk concerning the Hugging Face integration in PyCharm.
The Hugging Face Is Inside Your House
I could introduce this integration by just listing features, but that’s boring and there’s documentation for that. As an alternative, let’s walk through how we’d use all of it in practice. Let’s say I’m writing a Python app, and I determine I need the app to give you the chance to talk with users. Not only text chat, though – we would like the users to give you the chance to stick in images too, and for the app to naturally chat about them as well.
In the event you’re not super-familiar with the present state-of-the-art in machine learning, this might look like a terrifying demand, but don’t fear. Simply right click in your code, and choose “Insert HF Model”. You’ll get a dialog box:

Chatting with each images and text known as “image-text-to-text”: the user can supply images and text, and the model outputs text. Scroll down on the left until you discover it. By default, the model list might be sorted by Likes – but remember, older models often have plenty of likes built up even in the event that they’re probably not the state-of-the-art anymore. We will check how old models are by seeing the date they were last updated, just below the model name. Let’s pick something that’s each recent and popular: microsoft/Phi-3.5-vision-instruct.
You’ll be able to select “Use Model” for some model categories to robotically paste some basic code into your notebook, but what often works higher is to scroll through the Model Card on the fitting and grab any sample code. You’ll be able to see the complete model card to the fitting of the dialog box, exactly because it’s shown on Hugging Face Hub. Let’s try this and paste it into our code!

Your office cybersecurity person might complain about you copying a bit of random text from the web and running it without even reading all of it, but when that happens just call them a nerd and proceed regardless. And behold: We now have a working model that may happily chat about images – on this case, it reads and comments on screenshots of a Microsoft slide deck. Be at liberty to mess around with this instance. Try your personal chat, or your personal images. When you get it working, simply wrap this code right into a class and it’s able to go in your app. We just got state-of-the-art open-source machine learning in ten minutes without even opening an online browser.
These models could be large! In the event you’re getting memory errors, try using a GPU with more memory, or try reducing the 20 within the sample code. You can even remove device_map=”cuda” to place the model in CPU memory as a substitute, at the price of speed.
Quick Model Cards
Next, let’s change perspective in our little scenario. Now let’s say you’re not the writer of this code – you’re a coworker who has to review it. Possibly you’re the cybersecurity person from earlier, who’s still upset concerning the “nerd” comment. You have a look at this code snippet, and you have got no idea what you’re seeing. Don’t panic – just hover over the model name, and your complete model card immediately appears. You’ll be able to quickly confirm the origin of this model, and what its intended uses are.
(This can also be extremely helpful should you work on something else and completely forget the whole lot concerning the code you wrote two weeks ago)
The Local Model Cache
You would possibly notice that the model needs to be downloaded the primary time you run this code, but after that, it’s loaded rather more quickly. The model has been stored in your local cache. Remember the mysterious little 🤗 icon from earlier? Simply click it, and also you’ll get a list of the whole lot in your cache:

This can be a neat solution to find the models you’re working with straight away, and likewise to clear them out and avoid wasting disk space when you don’t need them anymore. It’s also very helpful for the two-week amnesia scenario – should you can’t remember the model you were using back then, it’s probably in here. Remember, though, that almost all useful, production-ready models in 2024 are going to be >1GB, so your cache can refill fast!
Python within the age of AI
At Hugging Face, we tend to think about open-source AI as being a natural extension of the open-source philosophy: Open software solves problems for developers and users, creating latest abilities for them to integrate into their code, and open models do the identical. There may be an inclination to be blinded by complexity, and to focus an excessive amount of on the implementation details because they’re all so novel and exciting, but models exist to do stuff for you. In the event you abstract away the small print of architecture and training, they’re fundamentally functions – tools in your code that can transform a certain sort of input right into a certain sort of output.
These features are thus a natural fit. Just as IDEs already pull up function signatures and docstrings for you, they may pull up sample code and model cards for trained models. Integrations like these make it easy to achieve over and import a chat or image recognition model as conveniently as you’ll import every other library. We predict it’s obvious that that is what the long run of code will appear to be, and we hope that you just find these features useful!
Download PyCharm to provide the Hugging Face integration a try.
[HF integration is a Pycharm Professional feature.]
Get a free 3-month PyCharm subscription using the PyCharm4HF code here.


