{"id":454377,"date":"2025-04-01T21:02:12","date_gmt":"2025-04-01T21:02:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=454377"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=454377","title":{"rendered":"<span>Gemma 3 Tutorial for Beginners \u2013 Google\u2019s Most Powerful Open AI<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Welcome back, AI enthusiasts! Today, we\u2019re exploring\u00a0<strong>Google\u2019s new Gemma 3 AI<\/strong>\u00a0\u2013 a powerful open-source model designed to operate on a single GPU. If you\u2019ve heard the hype about Gemma 3 being the \u201cmost powerful model you can use on one GPU,\u201d you\u2019re in the right place.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/115\/c3f\/d02\/115c3fd0276758b599ca10e555b0d2a2.png\" alt=\"Gemma 3\" title=\"Gemma 3\" width=\"950\" height=\"640\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/115\/c3f\/d02\/115c3fd0276758b599ca10e555b0d2a2.png\"\/><\/p>\n<div><figcaption>Gemma 3<\/figcaption><\/div>\n<\/figure>\n<h3>About Gemma 3<\/h3>\n<h4>What is Google Gemma 3?<\/h4>\n<p>Think of Gemma 3 as Google\u2019s answer to GPT-style models, but it\u2019s <strong>open<\/strong> and optimized to run anywhere \u2013 your laptop, a single server, or even a high-end phone!  It\u2019s the latest in Google\u2019s Gemma family of AI models. Google took the same core tech that powers their gigantic Gemini models and distilled it into Gemma 3. The result: a set of models you can actually download and run yourself. Gemma 3 is all about accessibility without sacrificing performance. In fact, the largest Gemma 3 model, with 27 billion parameters, ranks among the top open AI models in quality.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/109\/8f0\/38d\/1098f038dc553fd7127a3cb123c6a219.png\" alt=\"Chatbot Arena Elo scores\" title=\"Chatbot Arena Elo scores\" width=\"1427\" height=\"760\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/109\/8f0\/38d\/1098f038dc553fd7127a3cb123c6a219.png\"\/><\/p>\n<div><figcaption>Chatbot Arena Elo scores<\/figcaption><\/div>\n<\/figure>\n<h4>Understanding Gemma 3 Models<\/h4>\n<p>Gemma 3 comes in four sizes \u2013 1B, 4B, 12B, and 27B (that\u2019s \u201cB\u201d for billion parameters). The bigger, the smarter, generally. But even the 4B or 12B can handle a lot. It\u2019s multilingual (140+ languages out of the box) and even multimodal, meaning it can understand images combined with text. We\u2019ve only seen this in very advanced models like GPT-4. Plus, Gemma 3 has an expanded memory \u2013 a 128,000 token context window \u2013 basically, it can read and remember extremely long documents or conversations. For perspective, that\u2019s over 100 pages of text in one go! <\/p>\n<p>Google made <strong>Gemma 3 open for developers<\/strong>. You can download the model weights for free and run them locally or call Gemma 3 through an API. There is no need to pay per prompt if you host it yourself. It\u2019s licensed for commercial use with some responsible AI guidelines, so you could potentially build it into a product. This open-model approach is similar to Meta\u2019s LLaMA 2, but Google\u2019s taken it further with multimodal and high efficiency.<\/p>\n<p>You can use your favorite tools, such as <strong>Hugging Face Transformers, Ollama, PyTorch, Google AI Edge, UnSloth, vLLM, etc<\/strong>. In this tutorial, I&#8217;ll show you how to use it via Hugging Face. At the end of my tutorial, we&#8217;ll have a web application similar to ChatGPT that we will run locally.<\/p>\n<h4>Gemma 3\u2019s Key Features<\/h4>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/292\/693\/522\/292693522f709c1cebe0445d6c2774cd.png\" alt=\"Gemma 3\u2019s Key Features\" title=\"Gemma 3\u2019s Key Features\" width=\"1536\" height=\"1024\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/292\/693\/522\/292693522f709c1cebe0445d6c2774cd.png\"\/><\/p>\n<div><figcaption>Gemma 3\u2019s Key Features<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p><strong>Small but Strong.<\/strong> Gemma 3 is powerful; even the big 27B model can run on one GPU. It\u2019s faster and smaller than many other AIs.<\/p>\n<\/li>\n<li>\n<p><strong>It Reads Long Texts.<\/strong>\u00a0It can read and understand very long documents, such as books or contracts, all at once.<\/p>\n<\/li>\n<li>\n<p><strong>Understands Pictures and Text.<\/strong> You can show it an image and ask questions. It knows how to look at pictures and give competent answers.<\/p>\n<\/li>\n<li>\n<p><strong>Speaks 140+ Languages<\/strong>: Gemma works in many languages \u2014 like Spanish, French, Japanese, and more.<\/p>\n<\/li>\n<li>\n<p><strong>Gives Clean Data.<\/strong> It can reply in formats like JSON, so developers can use the answers in apps easily.<\/p>\n<\/li>\n<li>\n<p><strong>Runs on Smaller Devices.<\/strong> Smaller versions are available, so you can run it on laptops with less memory.<\/p>\n<\/li>\n<li>\n<p><strong>Built-in Safety.<\/strong> Google added ShieldGemma 2 tools to help keep it safe and block harmful content.<\/p>\n<\/li>\n<\/ul>\n<h4>Minimum Requirements to Run Gemma 3 Locally<\/h4>\n<p>If you want to run Gemma 3 locally on your computer, ensure your device meets the minimum requirements.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/de1\/dfe\/2f0\/de1dfe2f0b1cde1313adc75e6a6dc765.png\" alt=\"Minimum Requirements to Run Gemma 3 Locally\" title=\"Minimum Requirements to Run Gemma 3 Locally\" width=\"1536\" height=\"1024\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/de1\/dfe\/2f0\/de1dfe2f0b1cde1313adc75e6a6dc765.png\"\/><\/p>\n<div><figcaption>Minimum Requirements to Run Gemma 3 Locally<\/figcaption><\/div>\n<\/figure>\n<h3>How to Access Gemma 3<\/h3>\n<p>There are multiple ways how you can work with this model. In this tutorial, I&#8217;ll show you three ways:<\/p>\n<ul>\n<li>\n<p>Google AI Studio<\/p>\n<\/li>\n<li>\n<p>Hugging Face<\/p>\n<\/li>\n<li>\n<p>Google APIs<\/p>\n<\/li>\n<\/ul>\n<h4>How to Use Gemma 3 in Google AI Studio<\/h4>\n<ul>\n<li>\n<p>Open this link in your browser: <a href=\"https:\/\/aistudio.google.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/aistudio.google.com\/<\/a><\/p>\n<\/li>\n<li>\n<p>You\u2019ll need a Google account to use AI Studio.<\/p>\n<\/li>\n<li>\n<p> Click <strong>&#171;Create Prompt&#187;<\/strong>.<\/p>\n<\/li>\n<li>\n<p> In the <strong>Model Settings<\/strong>, select <strong>Gemma 3<\/strong> (you may see options like &#171;Gemma 27B&#187;, &#171;Gemma 4B&#187;, etc.).<\/p>\n<\/li>\n<li>\n<p>Type anything you want Gemma to help with \u2014 like writing, coding, or asking questions.<\/p>\n<\/li>\n<li>\n<p>Click the <strong>&#171;Run&#187;<\/strong> button to get a response from Gemma 3.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/045\/330\/a46\/045330a468f7ecf4f504a1e3f281aaca.png\" alt=\"How to Use Gemma 3 in Google AI Studio\" title=\"How to Use Gemma 3 in Google AI Studio\" width=\"1843\" height=\"998\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/045\/330\/a46\/045330a468f7ecf4f504a1e3f281aaca.png\"\/><\/p>\n<div><figcaption>How to Use Gemma 3 in Google AI Studio<\/figcaption><\/div>\n<\/figure>\n<h4>How to Use Gemma 3 with Hugging Face Transformers (Python)<\/h4>\n<p>If you\u2019re comfortable with Python, this is straightforward. Hugging Face has the Gemma 3 models on their hub. All you do is install the Transformers library and then download the model. I won&#8217;t explain all the steps in detail, but you can read my <a href=\"https:\/\/proflead.dev\/posts\/hugging-face-tutorial\/\" rel=\"noopener noreferrer nofollow\">full tutorial about Hugging Face<\/a>, <\/p>\n<p>Before we start, you would need:<\/p>\n<ul>\n<li>\n<p>Install IDE like <a href=\"https:\/\/code.visualstudio.com\/\" rel=\"noopener noreferrer nofollow\">VScode<\/a><\/p>\n<\/li>\n<li>\n<p>Install Python language<\/p>\n<\/li>\n<\/ul>\n<p>Then follow these steps:<\/p>\n<ul>\n<li>\n<p>Open <a href=\"https:\/\/huggingface.co\" rel=\"noopener noreferrer nofollow\">https:\/\/huggingface.co<\/a> and create an account there.<\/p>\n<\/li>\n<li>\n<p>Click the &#171;Models&#187; link in the top nav and filter the results by typing &#171;Gemma&#187; and selecting one of Google&#8217;s models from the list.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/667\/e27\/7be\/667e277be5fa783492b6aa13079188fb.png\" alt=\"How to Use Gemma 3 with Hugging Face Transformers (Python)\" title=\"How to Use Gemma 3 with Hugging Face Transformers (Python)\" width=\"1845\" height=\"1005\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/667\/e27\/7be\/667e277be5fa783492b6aa13079188fb.png\"\/><\/p>\n<div><figcaption>How to Use Gemma 3 with Hugging Face Transformers (Python)<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p>Select the desired model, e.g.,\u00a0<a href=\"https:\/\/huggingface.co\/google\/gemma-3-4b-it\" rel=\"noopener noreferrer nofollow\">https:\/\/huggingface.co\/google\/gemma-3-4b-it,<\/a>\u00a0and accept the license agreement. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8dc\/a82\/b38\/8dca82b386151c7949a00d50bd1299bf.png\" alt=\"Select the desired model and accept the license agreement\" title=\"Select the desired model and accept the license agreement\" width=\"1284\" height=\"914\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8dc\/a82\/b38\/8dca82b386151c7949a00d50bd1299bf.png\"\/><\/p>\n<div><figcaption>Select the desired model and accept the license agreement<\/figcaption><\/div>\n<\/figure>\n<\/li>\n<\/ul>\n<p>Then open your terminal and paste these commands one by one:<\/p>\n<pre><code class=\"bash\">python3 -m venv venv source venv\/bin\/activate pip install transformers datasets evaluate accelerate pip install torch<\/code><\/pre>\n<p>Then open your IDE and create a new file, e.g., <code>main.py<\/code>, with the following code:<\/p>\n<pre><code class=\"python\">from transformers import pipeline import torch  pipe = pipeline(     \"image-text-to-text\",     model=\"google\/gemma-3-4b-it\",     device=\"cpu\",     torch_dtype=torch.bfloat16 )  messages = [     {         \"role\": \"system\",         \"content\": [{\"type\": \"text\", \"text\": \"You are a helpful assistant.\"}]     },     {         \"role\": \"user\",         \"content\": [             {\"type\": \"image\", \"url\": \"https:\/\/huggingface.co\/datasets\/huggingface\/documentation-images\/resolve\/main\/p-blog\/candy.JPG\"},             {\"type\": \"text\", \"text\": \"What animal is on the candy?\"}         ]     } ]   output = pipe(text=messages, max_new_tokens=200) print(output[0][\"generated_text\"][-1][\"content\"])  <\/code><\/pre>\n<p>Run the Python code by using this command:<\/p>\n<pre><code>python3 main.py<\/code><\/pre>\n<p>In this example, we asked Gemma to look at the image from the URL and identify the animal on the candy. We used the Gemma 3 &#8212; 4B model and the device &#8212; CPU.<\/p>\n<p>The complete code with other examples you can find on my Git repo &#8212; <a href=\"https:\/\/github.com\/proflead\/gemma-3-tutorial\" rel=\"noopener noreferrer nofollow\">Gemma 3<\/a><\/p>\n<h4>How to Use Gemma 3 via Google&#8217;s API<\/h4>\n<p>As in the Hugging Face example, before we start, you would need:<\/p>\n<ul>\n<li>\n<p>Install IDE like <a href=\"https:\/\/code.visualstudio.com\/\" rel=\"noopener noreferrer nofollow\">VScode<\/a><\/p>\n<\/li>\n<li>\n<p>Install Python language<\/p>\n<\/li>\n<\/ul>\n<p>Then follow these steps:<\/p>\n<ul>\n<li>\n<p>Open <a href=\"https:\/\/aistudio.google.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/aistudio.google.com\/<\/a> and create a Google account if you don&#8217;t have one.<\/p>\n<\/li>\n<li>\n<p>Then click on the &#171;Get API key&#187; button. On this page, you need to generate an API key. We will need it to connect to Google Cloud API.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c9e\/f03\/c40\/c9ef03c4094308b30057a52eec526b41.png\" width=\"1843\" height=\"997\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c9e\/f03\/c40\/c9ef03c4094308b30057a52eec526b41.png\"\/><\/figure>\n<p>Then open your terminal and paste these commands one by one:<\/p>\n<pre><code class=\"perl\">pip install google-generativeai pip install google-genai<\/code><\/pre>\n<p>Then open your IDE and create a new file, e.g., google-cloud-api-terminal.py, with the following code:<\/p>\n<pre><code class=\"python\">import google.generativeai as genai  # Configure the API key genai.configure(api_key=\"[REPLACE-THIS-TEXT-WITH-YOUR-API-KEY]\")  # Initialize the GenerativeModel with the model name as a positional argument model = genai.GenerativeModel(\"gemma-3-27b-it\")  # Generate content response = model.generate_content(\"What is the latest version of iphone?\")  # Print the generated text print(response.text)<\/code><\/pre>\n<p>This example used a 27-billion parameters model and a simple text prompt.<\/p>\n<p>The complete code with other examples you can find on my Git repo &#8212; <a href=\"https:\/\/github.com\/proflead\/gemma-3-tutorial\" rel=\"noopener noreferrer nofollow\">Gemma 3<\/a><\/p>\n<h3>A Simple Web Application Similar To ChatGPT that Using Gemma 3<\/h3>\n<p>So, let&#8217;s collect everything together and create a simple web application that we can run locally on your computer. In this example, I&#8217;ll be using Google Cloud API, but you can use Hugging Face and download the model to your computer.<\/p>\n<p>We are going to use the <strong>chainlit library<\/strong>. Chainlit is an open-source Python package to build production-ready Conversational AI.<\/p>\n<p>Before we start, you would need:<\/p>\n<ul>\n<li>\n<p>Install IDE like <a href=\"https:\/\/code.visualstudio.com\/\" rel=\"noopener noreferrer nofollow\">VScode<\/a><\/p>\n<\/li>\n<li>\n<p>Install Python language<\/p>\n<\/li>\n<li>\n<p>Google&#8217;s API key is from Google AI studio (look at the previous section).<\/p>\n<\/li>\n<\/ul>\n<p>Then open your terminal and paste these commands one by one:<\/p>\n<pre><code class=\"python\">pip install google-generativeai pip install google-genai pip install chainlit<\/code><\/pre>\n<p>Then open your IDE and create a new file, e.g., google-cloud-web-interface.py, with the following code:<\/p>\n<pre><code class=\"python\">import chainlit as cl import google.generativeai as genai  # Configure the Generative AI client genai.configure(api_key=\"[REPLACE-THIS-TEXT-WITH-YOUR-API-KEY]\")  # Initialize the GenerativeModel model = genai.GenerativeModel(\"gemma-3-27b-it\")  @cl.on_message async def handle_message(message: cl.Message):     # Generate content based on the user's input     response = model.generate_content(contents=[message.content])     reply = response.text      # Send the generated response back to the user     await cl.Message(content=reply).send() <\/code><\/pre>\n<p>Run the Python code by using this command:<\/p>\n<pre><code>chainlit run google-cloud-web-interface.py<\/code><\/pre>\n<p>If everything is ok, you will see your web application at <a href=\"http:\/\/localhost:8000\/\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:8000\/<\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/582\/452\/b43\/582452b43355126388b766e1190420f9.png\" alt=\"A Simple Web Application Similar To ChatGPT that Using Gemma 3\" title=\"A Simple Web Application Similar To ChatGPT that Using Gemma 3\" width=\"1789\" height=\"999\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/582\/452\/b43\/582452b43355126388b766e1190420f9.png\"\/><\/p>\n<div><figcaption>A Simple Web Application Similar To ChatGPT that Using Gemma 3<\/figcaption><\/div>\n<\/figure>\n<h2>Video Tutorial<\/h2>\n<p>I have a video tutorial that explains everything in detail. You can find it on YouTube.<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/67eb66e91b6bd2ba7cd13285\" data-style=\"\" id=\"67eb66e91b6bd2ba7cd13285\" width=\"\"><\/div>\n<p><em>Watch on YouTube: <\/em><a href=\"https:\/\/youtu.be\/_IzgKu0xnmg?si=P0lDT81zxmJg6Gp9\" rel=\"noopener noreferrer nofollow\"><em>Gemma 3 Full Guide<\/em><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>In conclusion, Google Gemma 3 is a highly capable AI you can run locally and customize yourself. Whether you&#8217;re a developer refining it for a custom app or an enthusiast exploring AI on your PC, Gemma 3 offers immense possibilities. <\/p>\n<p>If you found this tutorial helpful, <strong>give it a thumbs up<\/strong> and <strong>subscribe<\/strong> for more cutting-edge AI content. Drop a comment if you have questions or if you did something cool with Gemma 3 \u2013 I&#8217;d love to hear about it. <\/p>\n<p>Thanks for reading, and until next time, happy coding! \ud83d\udc4b<\/p>\n<p>Cheers! \ud83d\ude09<\/p>\n<p><em>src: <\/em><a href=\"https:\/\/proflead.dev\/posts\/gemma-3-full-guide\/\" rel=\"noopener noreferrer nofollow\"><em>Gemma 3 tutorial<\/em><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/896290\/\"> https:\/\/habr.com\/ru\/articles\/896290\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Welcome back, AI enthusiasts! Today, we\u2019re exploring\u00a0<strong>Google\u2019s new Gemma 3 AI<\/strong>\u00a0\u2013 a powerful open-source model designed to operate on a single GPU. If you\u2019ve heard the hype about Gemma 3 being the \u201cmost powerful model you can use on one GPU,\u201d you\u2019re in the right place.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Gemma 3<\/figcaption><\/div>\n<\/figure>\n<h3>About Gemma 3<\/h3>\n<h4>What is Google Gemma 3?<\/h4>\n<p>Think of Gemma 3 as Google\u2019s answer to GPT-style models, but it\u2019s <strong>open<\/strong> and optimized to run anywhere \u2013 your laptop, a single server, or even a high-end phone!  It\u2019s the latest in Google\u2019s Gemma family of AI models. Google took the same core tech that powers their gigantic Gemini models and distilled it into Gemma 3. The result: a set of models you can actually download and run yourself. Gemma 3 is all about accessibility without sacrificing performance. In fact, the largest Gemma 3 model, with 27 billion parameters, ranks among the top open AI models in quality.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Chatbot Arena Elo scores<\/figcaption><\/div>\n<\/figure>\n<h4>Understanding Gemma 3 Models<\/h4>\n<p>Gemma 3 comes in four sizes \u2013 1B, 4B, 12B, and 27B (that\u2019s \u201cB\u201d for billion parameters). The bigger, the smarter, generally. But even the 4B or 12B can handle a lot. It\u2019s multilingual (140+ languages out of the box) and even multimodal, meaning it can understand images combined with text. We\u2019ve only seen this in very advanced models like GPT-4. Plus, Gemma 3 has an expanded memory \u2013 a 128,000 token context window \u2013 basically, it can read and remember extremely long documents or conversations. For perspective, that\u2019s over 100 pages of text in one go! <\/p>\n<p>Google made <strong>Gemma 3 open for developers<\/strong>. You can download the model weights for free and run them locally or call Gemma 3 through an API. There is no need to pay per prompt if you host it yourself. It\u2019s licensed for commercial use with some responsible AI guidelines, so you could potentially build it into a product. This open-model approach is similar to Meta\u2019s LLaMA 2, but Google\u2019s taken it further with multimodal and high efficiency.<\/p>\n<p>You can use your favorite tools, such as <strong>Hugging Face Transformers, Ollama, PyTorch, Google AI Edge, UnSloth, vLLM, etc<\/strong>. In this tutorial, I&#8217;ll show you how to use it via Hugging Face. At the end of my tutorial, we&#8217;ll have a web application similar to ChatGPT that we will run locally.<\/p>\n<h4>Gemma 3\u2019s Key Features<\/h4>\n<figure class=\"full-width\">\n<div><figcaption>Gemma 3\u2019s Key Features<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p><strong>Small but Strong.<\/strong> Gemma 3 is powerful; even the big 27B model can run on one GPU. It\u2019s faster and smaller than many other AIs.<\/p>\n<\/li>\n<li>\n<p><strong>It Reads Long Texts.<\/strong>\u00a0It can read and understand very long documents, such as books or contracts, all at once.<\/p>\n<\/li>\n<li>\n<p><strong>Understands Pictures and Text.<\/strong> You can show it an image and ask questions. It knows how to look at pictures and give competent answers.<\/p>\n<\/li>\n<li>\n<p><strong>Speaks 140+ Languages<\/strong>: Gemma works in many languages \u2014 like Spanish, French, Japanese, and more.<\/p>\n<\/li>\n<li>\n<p><strong>Gives Clean Data.<\/strong> It can reply in formats like JSON, so developers can use the answers in apps easily.<\/p>\n<\/li>\n<li>\n<p><strong>Runs on Smaller Devices.<\/strong> Smaller versions are available, so you can run it on laptops with less memory.<\/p>\n<\/li>\n<li>\n<p><strong>Built-in Safety.<\/strong> Google added ShieldGemma 2 tools to help keep it safe and block harmful content.<\/p>\n<\/li>\n<\/ul>\n<h4>Minimum Requirements to Run Gemma 3 Locally<\/h4>\n<p>If you want to run Gemma 3 locally on your computer, ensure your device meets the minimum requirements.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Minimum Requirements to Run Gemma 3 Locally<\/figcaption><\/div>\n<\/figure>\n<h3>How to Access Gemma 3<\/h3>\n<p>There are multiple ways how you can work with this model. In this tutorial, I&#8217;ll show you three ways:<\/p>\n<ul>\n<li>\n<p>Google AI Studio<\/p>\n<\/li>\n<li>\n<p>Hugging Face<\/p>\n<\/li>\n<li>\n<p>Google APIs<\/p>\n<\/li>\n<\/ul>\n<h4>How to Use Gemma 3 in Google AI Studio<\/h4>\n<ul>\n<li>\n<p>Open this link in your browser: <a href=\"https:\/\/aistudio.google.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/aistudio.google.com\/<\/a><\/p>\n<\/li>\n<li>\n<p>You\u2019ll need a Google account to use AI Studio.<\/p>\n<\/li>\n<li>\n<p> Click <strong>&#171;Create Prompt&#187;<\/strong>.<\/p>\n<\/li>\n<li>\n<p> In the <strong>Model Settings<\/strong>, select <strong>Gemma 3<\/strong> (you may see options like &#171;Gemma 27B&#187;, &#171;Gemma 4B&#187;, etc.).<\/p>\n<\/li>\n<li>\n<p>Type anything you want Gemma to help with \u2014 like writing, coding, or asking questions.<\/p>\n<\/li>\n<li>\n<p>Click the <strong>&#171;Run&#187;<\/strong> button to get a response from Gemma 3.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\">\n<div><figcaption>How to Use Gemma 3 in Google AI Studio<\/figcaption><\/div>\n<\/figure>\n<h4>How to Use Gemma 3 with Hugging Face Transformers (Python)<\/h4>\n<p>If you\u2019re comfortable with Python, this is straightforward. Hugging Face has the Gemma 3 models on their hub. All you do is install the Transformers library and then download the model. I won&#8217;t explain all the steps in detail, but you can read my <a href=\"https:\/\/proflead.dev\/posts\/hugging-face-tutorial\/\" rel=\"noopener noreferrer nofollow\">full tutorial about Hugging Face<\/a>, <\/p>\n<p>Before we start, you would need:<\/p>\n<ul>\n<li>\n<p>Install IDE like <a href=\"https:\/\/code.visualstudio.com\/\" rel=\"noopener noreferrer nofollow\">VScode<\/a><\/p>\n<\/li>\n<li>\n<p>Install Python language<\/p>\n<\/li>\n<\/ul>\n<p>Then follow these steps:<\/p>\n<ul>\n<li>\n<p>Open <a href=\"https:\/\/huggingface.co\" rel=\"noopener noreferrer nofollow\">https:\/\/huggingface.co<\/a> and create an account there.<\/p>\n<\/li>\n<li>\n<p>Click the &#171;Models&#187; link in the top nav and filter the results by typing &#171;Gemma&#187; and selecting one of Google&#8217;s models from the list.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\">\n<div><figcaption>How to Use Gemma 3 with Hugging Face Transformers (Python)<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p>Select the desired model, e.g.,\u00a0<a href=\"https:\/\/huggingface.co\/google\/gemma-3-4b-it\" rel=\"noopener noreferrer nofollow\">https:\/\/huggingface.co\/google\/gemma-3-4b-it,<\/a>\u00a0and accept the license agreement. <\/p>\n<figure class=\"full-width\">\n<div><figcaption>Select the desired model and accept the license agreement<\/figcaption><\/div>\n<\/figure>\n<\/li>\n<\/ul>\n<p>Then open your terminal and paste these commands one by one:<\/p>\n<pre><code class=\"bash\">python3 -m venv venv source venv\/bin\/activate pip install transformers datasets evaluate accelerate pip install torch<\/code><\/pre>\n<p>Then open your IDE and create a new file, e.g., <code>main.py<\/code>, with the following code:<\/p>\n<pre><code class=\"python\">from transformers import pipeline import torch  pipe = pipeline(     \"image-text-to-text\",     model=\"google\/gemma-3-4b-it\",     device=\"cpu\",     torch_dtype=torch.bfloat16 )  messages = [     {         \"role\": \"system\",         \"content\": [{\"type\": \"text\", \"text\": \"You are a helpful assistant.\"}]     },     {         \"role\": \"user\",         \"content\": [             {\"type\": \"image\", \"url\": \"https:\/\/huggingface.co\/datasets\/huggingface\/documentation-images\/resolve\/main\/p-blog\/candy.JPG\"},             {\"type\": \"text\", \"text\": \"What animal is on the candy?\"}         ]     } ]   output = pipe(text=messages, max_new_tokens=200) print(output[0][\"generated_text\"][-1][\"content\"])  <\/code><\/pre>\n<p>Run the Python code by using this command:<\/p>\n<pre><code>python3 main.py<\/code><\/pre>\n<p>In this example, we asked Gemma to look at the image from the URL and identify the animal on the candy. We used the Gemma 3 &#8212; 4B model and the device &#8212; CPU.<\/p>\n<p>The complete code with other examples you can find on my Git repo &#8212; <a href=\"https:\/\/github.com\/proflead\/gemma-3-tutorial\" rel=\"noopener noreferrer nofollow\">Gemma 3<\/a><\/p>\n<h4>How to Use Gemma 3 via Google&#8217;s API<\/h4>\n<p>As in the Hugging Face example, before we start, you would need:<\/p>\n<ul>\n<li>\n<p>Install IDE like <a href=\"https:\/\/code.visualstudio.com\/\" rel=\"noopener noreferrer nofollow\">VScode<\/a><\/p>\n<\/li>\n<li>\n<p>Install Python language<\/p>\n<\/li>\n<\/ul>\n<p>Then follow these steps:<\/p>\n<ul>\n<li>\n<p>Open <a href=\"https:\/\/aistudio.google.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/aistudio.google.com\/<\/a> and create a Google account if you don&#8217;t have one.<\/p>\n<\/li>\n<li>\n<p>Then click on the &#171;Get API key&#187; button. On this page, you need to generate an API key. We will need it to connect to Google Cloud API.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><\/figure>\n<p>Then open your terminal and paste these commands one by one:<\/p>\n<pre><code class=\"perl\">pip install google-generativeai pip install google-genai<\/code><\/pre>\n<p>Then open your IDE and create a new file, e.g., google-cloud-api-terminal.py, with the following code:<\/p>\n<pre><code class=\"python\">import google.generativeai as genai  # Configure the API key genai.configure(api_key=\"[REPLACE-THIS-TEXT-WITH-YOUR-API-KEY]\")  # Initialize the GenerativeModel with the model name as a positional argument model = genai.GenerativeModel(\"gemma-3-27b-it\")  # Generate content response = model.generate_content(\"What is the latest version of iphone?\")  # Print the generated text print(response.text)<\/code><\/pre>\n<p>This example used a 27-billion parameters model and a simple text prompt.<\/p>\n<p>The complete code with other examples you can find on my Git repo &#8212; <a href=\"https:\/\/github.com\/proflead\/gemma-3-tutorial\" rel=\"noopener noreferrer nofollow\">Gemma 3<\/a><\/p>\n<h3>A Simple Web Application Similar To ChatGPT that Using Gemma 3<\/h3>\n<p>So, let&#8217;s collect everything together and create a simple web application that we can run locally on your computer. In this example, I&#8217;ll be using Google Cloud API, but you can use Hugging Face and download the model to your computer.<\/p>\n<p>We are going to use the <strong>chainlit library<\/strong>. Chainlit is an open-source Python package to build production-ready Conversational AI.<\/p>\n<p>Before we start, you would need:<\/p>\n<ul>\n<li>\n<p>Install IDE like <a href=\"https:\/\/code.visualstudio.com\/\" rel=\"noopener noreferrer nofollow\">VScode<\/a><\/p>\n<\/li>\n<li>\n<p>Install Python language<\/p>\n<\/li>\n<li>\n<p>Google&#8217;s API key is from Google AI studio (look at the previous section).<\/p>\n<\/li>\n<\/ul>\n<p>Then open your terminal and paste these commands one by one:<\/p>\n<pre><code class=\"python\">pip install google-generativeai pip install google-genai pip install chainlit<\/code><\/pre>\n<p>Then open your IDE and create a new file, e.g., google-cloud-web-interface.py, with the following code:<\/p>\n<pre><code class=\"python\">import chainlit as cl import google.generativeai as genai  # Configure the Generative AI client genai.configure(api_key=\"[REPLACE-THIS-TEXT-WITH-YOUR-API-KEY]\")  # Initialize the GenerativeModel model = genai.GenerativeModel(\"gemma-3-27b-it\")  @cl.on_message async def handle_message(message: cl.Message):     # Generate content based on the user's input     response = model.generate_content(contents=[message.content])     reply = response.text      # Send the generated response back to the user     await cl.Message(content=reply).send() <\/code><\/pre>\n<p>Run the Python code by using this command:<\/p>\n<pre><code>chainlit run google-cloud-web-interface.py<\/code><\/pre>\n<p>If everything is ok, you will see your web application at <a href=\"http:\/\/localhost:8000\/\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:8000\/<\/a><\/p>\n<figure class=\"full-width\">\n<div><figcaption>A Simple Web Application Similar To ChatGPT that Using Gemma 3<\/figcaption><\/div>\n<\/figure>\n<h2>Video Tutorial<\/h2>\n<p>I have a video tutorial that explains everything in detail. You can find it on YouTube.<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/67eb66e91b6bd2ba7cd13285\" data-style=\"\" id=\"67eb66e91b6bd2ba7cd13285\" width=\"\"><\/div>\n<p><em>Watch on YouTube: <\/em><a href=\"https:\/\/youtu.be\/_IzgKu0xnmg?si=P0lDT81zxmJg6Gp9\" rel=\"noopener noreferrer nofollow\"><em>Gemma 3 Full Guide<\/em><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>In conclusion, Google Gemma 3 is a highly capable AI you can run locally and customize yourself. Whether you&#8217;re a developer refining it for a custom app or an enthusiast exploring AI on your PC, Gemma 3 offers immense possibilities. <\/p>\n<p>If you found this tutorial helpful, <strong>give it a thumbs up<\/strong> and <strong>subscribe<\/strong> for more cutting-edge AI content. Drop a comment if you have questions or if you did something cool with Gemma 3 \u2013 I&#8217;d love to hear about it. <\/p>\n<p>Thanks for reading, and until next time, happy coding! \ud83d\udc4b<\/p>\n<p>Cheers! \ud83d\ude09<\/p>\n<p><em>src: <\/em><a href=\"https:\/\/proflead.dev\/posts\/gemma-3-full-guide\/\" rel=\"noopener noreferrer nofollow\"><em>Gemma 3 tutorial<\/em><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/896290\/\"> https:\/\/habr.com\/ru\/articles\/896290\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-454377","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/454377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=454377"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/454377\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=454377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=454377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=454377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}