Jean Louis commited on
Commit
01a937e
·
1 Parent(s): 0c3183e

Updated HTML files and CSS

Browse files
Files changed (1) hide show
  1. 01-prepare-python.html +74 -62
01-prepare-python.html CHANGED
@@ -11,105 +11,121 @@
11
  <body>
12
  <h1>Prepare Python environment to download Hugging Face models</h1>
13
 
14
- <p>This guide will help you install the necessary <a href="https://huggingface.co">Hugging
15
- Face</a> packages and tools to download and use
16
- models from the Hugging Face Hub.</p>
 
17
 
18
  <p>Follow this guide, or <a href="index.html">return to the main page</a> if needed.</p>
19
 
20
  <hr />
21
 
22
- <h2>1. Install <code>transformers</code> Package</h2>
23
 
24
- <p>The <code>transformers</code> package is used to load and use Hugging Face models in Python.</p>
25
 
26
- <h3>Installation</h3>
27
-
28
- <p>Run the following command in your terminal or command prompt:</p>
29
 
30
  <p><code>bash
31
- pip install transformers
32
  </code></p>
33
 
34
- <h3>Verify Installation</h3>
 
 
 
 
 
 
 
 
 
35
 
36
- <p>To confirm the installation was successful, run:</p>
 
 
 
 
 
 
 
 
37
 
38
  <p><code>bash
39
- python -c "from transformers import pipeline; print('Installation successful!')"
 
 
 
 
 
40
  </code></p>
41
 
42
  <hr />
43
 
44
- <h2>2. Install <code>huggingface_hub</code> Package</h2>
45
 
46
- <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>
47
 
48
- <h3>Installation</h3>
49
 
50
- <p>Run the following command:</p>
51
 
52
  <p><code>bash
53
- pip install huggingface_hub
54
  </code></p>
55
 
56
  <h3>Verify Installation</h3>
57
 
58
- <p>After installation, check if the <code>huggingface-cli</code> is available:</p>
59
 
60
  <p><code>bash
61
- huggingface-cli --help
 
62
  </code></p>
63
 
64
  <hr />
65
 
66
- <h2>3. Using <code>huggingface-cli</code></h2>
67
-
68
- <p>The <code>huggingface-cli</code> tool allows you to interact with the Hugging Face Hub directly from the command line.</p>
69
 
70
- <h3>Common Commands</h3>
71
 
72
- <h3>Log in to Hugging Face</h3>
73
 
74
- <p>To log in to your Hugging Face account:</p>
75
 
76
- <p><code>
77
- huggingface-cli login
78
  </code></p>
79
 
80
- <h3>Download a Model</h3>
81
 
82
- <p>To download a model (e.g., <code>gpt2</code>):</p>
83
-
84
- <p><code>
85
- huggingface-cli download gpt2
86
- </code></p>
87
 
88
- <h3>List Available Commands</h3>
89
 
90
- <p>To see all available commands and options:</p>
91
 
92
- <p><code>
93
- huggingface-cli --help
94
- </code></p>
95
 
96
- <hr />
 
97
 
98
- <h2>4. Example: Download and Use a Model</h2>
99
 
100
- <p>Here’s an example of downloading and using a model in Python:</p>
 
 
101
 
102
- <pre>
103
- from transformers import pipeline
104
 
105
- # Download and load a model
106
- generator = pipeline("text-generation", model="gpt2")
 
107
 
108
- # Generate text
109
- output = generator("Hello, how are you?", max_length=50)
110
- print(output)
111
- </pre>
112
 
 
 
113
 
114
  <hr />
115
 
@@ -124,24 +140,20 @@ print(output)
124
  </thead>
125
  <tbody>
126
  <tr>
127
- <td> <code>pip install transformers</code> </td>
128
- <td> Install the <code>transformers</code> package. </td>
129
- </tr>
130
- <tr>
131
- <td> <code>pip install huggingface_hub</code> </td>
132
- <td> Install the <code>huggingface_hub</code> package. </td>
133
  </tr>
134
  <tr>
135
- <td> <code>huggingface-cli --help</code> </td>
136
- <td> List all available <code>huggingface-cli</code> commands. </td>
137
  </tr>
138
  <tr>
139
- <td> <code>huggingface-cli login</code> </td>
140
- <td> Log in to your Hugging Face account. </td>
141
  </tr>
142
  <tr>
143
- <td> <code>huggingface-cli download gpt2</code> </td>
144
- <td> Download the <code>gpt2</code> model. </td>
145
  </tr>
146
  </tbody>
147
  </table>
@@ -149,7 +161,7 @@ print(output)
149
 
150
  <hr />
151
 
152
- <p>Now you’re ready to use Hugging Face models and tools in Python! 🚀</p>
153
 
154
  <h1>Proceed to next step</h1>
155
 
 
11
  <body>
12
  <h1>Prepare Python environment to download Hugging Face models</h1>
13
 
14
+ <p>This guide will walk you through setting up a Python environment named
15
+ <strong><code>empower</code></strong>, installing the necessary Hugging Face packages, and
16
+ downloading and using the <strong><code>microsoft/Phi-4-mini-instruct</code></strong> model on
17
+ a GNU/Linux system.</p>
18
 
19
  <p>Follow this guide, or <a href="index.html">return to the main page</a> if needed.</p>
20
 
21
  <hr />
22
 
23
+ <h2>1. Set Up Python Environment</h2>
24
 
25
+ <h3>Check Python Installation</h3>
26
 
27
+ <p>Ensure Python 3 is installed by running:</p>
 
 
28
 
29
  <p><code>bash
30
+ python3 --version
31
  </code></p>
32
 
33
+ <p>If Python is not installed, install it using your package manager. For example:</p>
34
+
35
+ <ul>
36
+ <li><p>On Debian/Ubuntu:</p>
37
+
38
+ <p><code>bash
39
+ sudo apt update
40
+ sudo apt install python3 python3-venv
41
+ </code></p></li>
42
+ <li><p>On Fedora:</p>
43
 
44
+ <p><code>bash
45
+ sudo dnf install python3
46
+ </code></p></li>
47
+ </ul>
48
+
49
+
50
+ <h3>Create a Virtual Environment</h3>
51
+
52
+ <p>Create a virtual environment named <strong><code>empower</code></strong>:</p>
53
 
54
  <p><code>bash
55
+ python3 -m venv empower
56
+ </code></p>
57
+
58
+ <p>Activate the virtual environment:
59
+ <code>bash
60
+ source empower/bin/activate
61
  </code></p>
62
 
63
  <hr />
64
 
65
+ <h2>2. Install Hugging Face Packages</h2>
66
 
67
+ <p>Install the necessary Hugging Face packages to interact with models and the Hugging Face Hub.</p>
68
 
69
+ <h3>Install <code>transformers</code> and <code>huggingface_hub</code></h3>
70
 
71
+ <p>Run the following command to install both packages:</p>
72
 
73
  <p><code>bash
74
+ pip install transformers huggingface_hub
75
  </code></p>
76
 
77
  <h3>Verify Installation</h3>
78
 
79
+ <p>Check if the packages are installed correctly:</p>
80
 
81
  <p><code>bash
82
+ python3 -c "from transformers import pipeline; print('Transformers installed successfully!')"
83
+ python3 -c "from huggingface_hub import HfApi; print('Hugging Face Hub installed successfully!')"
84
  </code></p>
85
 
86
  <hr />
87
 
88
+ <h2>3. Download the <code>microsoft/Phi-4-mini-instruct</code> Model</h2>
 
 
89
 
90
+ <p>To download and use the <strong><code>microsoft/Phi-4-mini-instruct</code></strong> model, follow these steps.</p>
91
 
92
+ <h3>Using <code>huggingface-cli</code> to Download the Model</h3>
93
 
94
+ <p>Run the following command to download the model:</p>
95
 
96
+ <p><code>bash
97
+ huggingface-cli download microsoft/Phi-4-mini-instruct
98
  </code></p>
99
 
100
+ <p>This will download the model files to your current directory.</p>
101
 
102
+ <hr />
 
 
 
 
103
 
104
+ <h2>4. Load and Use the Model in Python</h2>
105
 
106
+ <p>Once the model is downloaded, you can load and use it in your Python code.</p>
107
 
108
+ <h3>Example Code</h3>
 
 
109
 
110
+ <p>```python
111
+ from transformers import AutoModelForCausalLM, AutoTokenizer</p>
112
 
113
+ <h1>Load the model and tokenizer</h1>
114
 
115
+ <p>model_name = &ldquo;microsoft/Phi-4-mini-instruct&rdquo;
116
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
117
+ model = AutoModelForCausalLM.from_pretrained(model_name)</p>
118
 
119
+ <h1>Generate text</h1>
 
120
 
121
+ <p>input_text = &ldquo;What is the capital of France?&rdquo;
122
+ inputs = tokenizer(input_text, return_tensors=&ldquo;pt&rdquo;)
123
+ outputs = model.generate(**inputs, max_length=50)</p>
124
 
125
+ <h1>Decode and print the output</h1>
 
 
 
126
 
127
+ <p>print(tokenizer.decode(outputs[0], skip_special_tokens=True))
128
+ ```</p>
129
 
130
  <hr />
131
 
 
140
  </thead>
141
  <tbody>
142
  <tr>
143
+ <td> <code>python3 -m venv empower</code> </td>
144
+ <td> Create a virtual environment named <code>empower</code>. </td>
 
 
 
 
145
  </tr>
146
  <tr>
147
+ <td> <code>source empower/bin/activate</code> </td>
148
+ <td> Activate the <code>empower</code> environment. </td>
149
  </tr>
150
  <tr>
151
+ <td> <code>pip install transformers huggingface_hub</code> </td>
152
+ <td> Install Hugging Face packages. </td>
153
  </tr>
154
  <tr>
155
+ <td> <code>huggingface-cli download microsoft/Phi-4-mini-instruct</code> </td>
156
+ <td> Download the model. </td>
157
  </tr>
158
  </tbody>
159
  </table>
 
161
 
162
  <hr />
163
 
164
+ <p>Now you’re ready to use the <strong><code>microsoft/Phi-4-mini-instruct</code></strong> model in your Python projects on GNU/Linux! 🚀</p>
165
 
166
  <h1>Proceed to next step</h1>
167