Spaces:
Running
Running
<html> | |
<head> | |
<meta name="GENERATOR" content="mkd2html 2.2.7 GITHUB_CHECKBOX"> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<link rel="stylesheet" | |
type="text/css" | |
href="header.css" /> | |
<title></title> | |
</head> | |
<body> | |
<h1>Prepare Python environment to download Hugging Face models</h1> | |
<p>This guide will help you install the necessary Hugging Face packages | |
and tools to download and use models from the Hugging Face Hub.</p> | |
<hr /> | |
<h2>1. Install <code>transformers</code> Package</h2> | |
<p>The <code>transformers</code> package is used to load and use Hugging Face models in Python.</p> | |
<h3>Installation</h3> | |
<p>Run the following command in your terminal or command prompt:</p> | |
<p><code>bash | |
pip install transformers | |
</code></p> | |
<h3>Verify Installation</h3> | |
<p>To confirm the installation was successful, run:</p> | |
<p><code>bash | |
python -c "from transformers import pipeline; print('Installation successful!')" | |
</code></p> | |
<hr /> | |
<h2>2. Install <code>huggingface_hub</code> Package</h2> | |
<p>The <code>huggingface_hub</code> package provides the <code>huggingface-cli</code> tool for interacting with the Hugging Face Hub (e.g., downloading models, uploading files, etc.).</p> | |
<h3>Installation</h3> | |
<p>Run the following command:</p> | |
<p><code>bash | |
pip install huggingface_hub | |
</code></p> | |
<h3>Verify Installation</h3> | |
<p>After installation, check if the <code>huggingface-cli</code> is available:</p> | |
<p><code>bash | |
huggingface-cli --help | |
</code></p> | |
<hr /> | |
<h2>3. Using <code>huggingface-cli</code></h2> | |
<p>The <code>huggingface-cli</code> tool allows you to interact with the Hugging Face Hub directly from the command line.</p> | |
<h3>Common Commands</h3> | |
<h3>Log in to Hugging Face</h3> | |
<p>To log in to your Hugging Face account:</p> | |
<p><code>bash | |
huggingface-cli login | |
</code></p> | |
<h3>Download a Model</h3> | |
<p>To download a model (e.g., <code>gpt2</code>):</p> | |
<p><code>bash | |
huggingface-cli download gpt2 | |
</code></p> | |
<h3>List Available Commands</h3> | |
<p>To see all available commands and options:</p> | |
<p><code>bash | |
huggingface-cli --help | |
</code></p> | |
<hr /> | |
<h2>4. Example: Download and Use a Model</h2> | |
<p>Here’s an example of downloading and using a model in Python:</p> | |
<pre> | |
from transformers import pipeline | |
# Download and load a model | |
generator = pipeline("text-generation", model="gpt2") | |
# Generate text | |
output = generator("Hello, how are you?", max_length=50) | |
print(output) | |
</pre> | |
<hr /> | |
<h2>5. Summary of Commands</h2> | |
<table> | |
<thead> | |
<tr> | |
<th> Command </th> | |
<th> Description </th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td> <code>pip install transformers</code> </td> | |
<td> Install the <code>transformers</code> package. </td> | |
</tr> | |
<tr> | |
<td> <code>pip install huggingface_hub</code> </td> | |
<td> Install the <code>huggingface_hub</code> package. </td> | |
</tr> | |
<tr> | |
<td> <code>huggingface-cli --help</code> </td> | |
<td> List all available <code>huggingface-cli</code> commands. </td> | |
</tr> | |
<tr> | |
<td> <code>huggingface-cli login</code> </td> | |
<td> Log in to your Hugging Face account. </td> | |
</tr> | |
<tr> | |
<td> <code>huggingface-cli download gpt2</code> </td> | |
<td> Download the <code>gpt2</code> model. </td> | |
</tr> | |
</tbody> | |
</table> | |
<hr /> | |
<p>Now you’re ready to use Hugging Face models and tools in Python! 🚀</p> | |
<h1>Proceed to next step</h1> | |
<p><a href="index.html">Proceed to next step.</a></p> | |
</body> | |
</html> | |