{"id":378556,"date":"2024-06-10T15:01:11","date_gmt":"2024-06-10T15:01:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=378556"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=378556","title":{"rendered":"<span>From Scratch to AI Chatbot: Using Python and Gemini API<\/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>In this article, we are going to do something really cool: we will build a chatbot using Python and the Gemini API. This will be a web-based assistant and could be the beginning of your own AI project. It&#8217;s beginner-friendly, and I will guide you through it step-by-step. By the end, you&#8217;ll have your own AI assistant!<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6667010aaeb5569d7b91442e\" data-style=\"\" id=\"6667010aaeb5569d7b91442e\" width=\"\"><\/div>\n<p><a href=\"https:\/\/www.youtube.com\/@proflead\/videos?sub_confirmation=1\" rel=\"noopener noreferrer nofollow\">Visit my YouTube Channel<\/a><\/p>\n<h3>What You&#8217;ll Need<\/h3>\n<ul>\n<li>\n<p>IDE (I recommend Visual Studio Code)<\/p>\n<\/li>\n<li>\n<p>Gemini API key<\/p>\n<\/li>\n<li>\n<p>Python<\/p>\n<\/li>\n<li>\n<p>Python libraries<\/p>\n<\/li>\n<\/ul>\n<h3>Download IDE &#8212; VS code<\/h3>\n<p>You can use any IDE you like, but if you don\u2019t have one, please download VS Code. It\u2019s really powerful and easy to use. Here&#8217;s the link:\u00a0 <a href=\"https:\/\/code.visualstudio.com\/download\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/code.visualstudio.com\/download<\/u><\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/78a\/d29\/a5f\/78ad29a5f57b94acb000f5dd85377a01.png\" alt=\"Download IDE - VS code\" title=\"Download IDE - VS code\" width=\"1319\" height=\"748\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/78a\/d29\/a5f\/78ad29a5f57b94acb000f5dd85377a01.png\"\/><\/p>\n<div><figcaption>Download IDE &#8212; VS code<\/figcaption><\/div>\n<\/figure>\n<h3>Gemini API<\/h3>\n<h4>Create a Google Cloud Project<\/h4>\n<p>Before we obtain an API key, we need to create a project in Google Cloud. To create a project, please follow this link: <a href=\"https:\/\/console.cloud.google.com\/cloud-resource-manager\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/console.cloud.google.com\/cloud-resource-manager<\/u><\/a>\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/340\/69d\/e2d\/34069de2d870f70a321e835dc5d75de7.png\" alt=\"Create a Google Cloud Project\" title=\"Create a Google Cloud Project\" width=\"1090\" height=\"634\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/340\/69d\/e2d\/34069de2d870f70a321e835dc5d75de7.png\"\/><\/p>\n<div><figcaption>Create a Google Cloud Project<\/figcaption><\/div>\n<\/figure>\n<p>After the project is created, we are ready to request an API key.<\/p>\n<h4>How to Get Gemini API Key<\/h4>\n<p>To get the API key, visit<a href=\"https:\/\/aistudio.google.com\/app\/apikey\" rel=\"noopener noreferrer nofollow\"> <u>https:\/\/aistudio.google.com\/app\/apikey<\/u><\/a> and click on the &#171;Create API key&#187; button.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8f5\/c43\/816\/8f5c43816f0be9e69c19a6f0e76e96c9.png\" alt=\"How to Get Gemini API Key\" title=\"How to Get Gemini API Key\" width=\"1346\" height=\"644\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f5\/c43\/816\/8f5c43816f0be9e69c19a6f0e76e96c9.png\"\/><\/p>\n<div><figcaption>How to Get Gemini API Key<\/figcaption><\/div>\n<\/figure>\n<p>Then, select the project that you created in the previous step from the drop-down menu and click &#171;Generate API key\u201d.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/273\/197\/935\/273197935992bd05400c54168fab0d58.png\" alt=\"How to Get Gemini API Key\" title=\"How to Get Gemini API Key\" width=\"743\" height=\"268\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/273\/197\/935\/273197935992bd05400c54168fab0d58.png\"\/><\/p>\n<div><figcaption>How to Get Gemini API Key<\/figcaption><\/div>\n<\/figure>\n<p>Copy the key; we\u2019ll need it in the next steps.<\/p>\n<h3>Install Python<\/h3>\n<p><strong>Windows:<\/strong> Download the installer from <a href=\"https:\/\/www.python.org\/downloads\/windows\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.python.org\/downloads\/windows\/<\/u><\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8a6\/d98\/126\/8a6d981261a8cb5fd6e75dfdf570f0ae.png\" alt=\"Install Python\" title=\"Install Python\" width=\"1319\" height=\"748\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8a6\/d98\/126\/8a6d981261a8cb5fd6e75dfdf570f0ae.png\"\/><\/p>\n<div><figcaption>Install Python<\/figcaption><\/div>\n<\/figure>\n<p><strong>Linux (Ubuntu\/Debian):<\/strong>\u00a0Use this command in your terminal window:<\/p>\n<p><code>sudo apt-get install python3<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f4c\/179\/800\/f4c179800617bac8751f1de858711e3e.png\" alt=\"Linux (Ubuntu\/Debian)\" title=\"Linux (Ubuntu\/Debian)\" width=\"1319\" height=\"748\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f4c\/179\/800\/f4c179800617bac8751f1de858711e3e.png\"\/><\/p>\n<div><figcaption>Linux (Ubuntu\/Debian)<\/figcaption><\/div>\n<\/figure>\n<h3>Install Python Libraries<\/h3>\n<p>For the next steps, you need to use the terminal. If you are on Windows, you can use <a href=\"https:\/\/apps.microsoft.com\/detail\/9n0dx20hk701?rtc=1&amp;hl=en-us\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/apps.microsoft.com\/detail\/9n0dx20hk701?rtc=1&amp;hl=en-us<\/u><\/a> <\/p>\n<h4>Install PIP<\/h4>\n<p>After we set up Python, we need to set up the pip package installer for Python.<\/p>\n<p><code>sudo apt install python3-pip<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1b6\/98a\/5fa\/1b698a5facedb5470748d8ebbf477a51.png\" alt=\"Install PIP\" title=\"Install PIP\" width=\"1360\" height=\"731\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1b6\/98a\/5fa\/1b698a5facedb5470748d8ebbf477a51.png\"\/><\/p>\n<div><figcaption>Install PIP<\/figcaption><\/div>\n<\/figure>\n<h4>Set Up a Virtual Environment<\/h4>\n<p>The next step is to set up virtual environments for our project to manage dependencies separately.<\/p>\n<p>Use this command:<\/p>\n<p><code>sudo apt install python3-venv<\/code>\u00a0<\/p>\n<p>The command python3 -m venv myprojectenv is used to create a virtual environment for a Python project:<\/p>\n<p><code>python3 -m venv myprojectenv<\/code><\/p>\n<p>The command source myprojectenv\/bin\/activate is used to activate the virtual environment:<\/p>\n<p><code>source myprojectenv\/bin\/activate<\/code><\/p>\n<h4>Install LangChain<\/h4>\n<p>LangChain is a framework designed to simplify the creation of applications using large language models.<\/p>\n<p>Use this command:<\/p>\n<p><code>pip install langchain-core<\/code><\/p>\n<h4>Install LangChain-Google-GenAI<\/h4>\n<p>Use this command:<\/p>\n<p><code>pip install langchain-google-genai<\/code><\/p>\n<p>This package contains the LangChain integrations for Gemini through their generative-ai SDK.<\/p>\n<p>Once you\u2019ve done that, we are ready to go to the next steps.<\/p>\n<h4>Install Flask<\/h4>\n<p>Once the virtual environment is activated, we can use pip to set up Flask.<\/p>\n<p>Use this command:<\/p>\n<p><code>pip install Flask<\/code><\/p>\n<h3>Create a ChatBot with the Python Flask Framework<\/h3>\n<p>First, let\u2019s create a directory for our app.<\/p>\n<p>Use these commands:<\/p>\n<p><code>mkdir myflaskapp<\/code><\/p>\n<p><code>cd myflaskapp<\/code><\/p>\n<p>Inside the directory, create a file for our app and call it &#171;app.py&#187;.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/61a\/a47\/cbf\/61aa47cbf333b93ca5c403d7d732418c.png\" alt=\"Create a ChatBot with the Python Flask Framework\" title=\"Create a ChatBot with the Python Flask Framework\" width=\"1360\" height=\"731\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/61a\/a47\/cbf\/61aa47cbf333b93ca5c403d7d732418c.png\"\/><\/p>\n<div><figcaption>Create a ChatBot with the Python Flask Framework<\/figcaption><\/div>\n<\/figure>\n<p>Then add the following content:<\/p>\n<p><code>from flask import Flask<\/code><\/p>\n<p><code>app = Flask(name)<\/code><\/p>\n<p><code><a class=\"mention\" href=\"\/users\/app\">@app<\/a>.route('\/')<\/code><\/p>\n<p><code>def home():<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0return \"Hello, Flask!\"<\/code><\/p>\n<p><code>if name == 'main':<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0app.run(debug=True)<\/code><\/p>\n<p>To make sure that our app is working fine, let\u2019s run it.<\/p>\n<p>Use this command:<\/p>\n<p><code>python3 app.py<\/code><\/p>\n<p>If everything is okay, you will be able to access your Flask app at http:\/\/<u>127.0.0.1:5000<\/u>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2bc\/430\/bc9\/2bc430bc94efa3fde5f440d2ceb40fa7.png\" width=\"1360\" height=\"731\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2bc\/430\/bc9\/2bc430bc94efa3fde5f440d2ceb40fa7.png\"\/><\/figure>\n<h4>Create an HTML Page for the Flask App<\/h4>\n<p>You can create your own HTML or use the example provided.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cd8\/ec8\/4ba\/cd8ec84ba2c62a47782fa42d88886772.png\" width=\"1360\" height=\"731\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd8\/ec8\/4ba\/cd8ec84ba2c62a47782fa42d88886772.png\"\/><\/figure>\n<p>You can download it from here:<a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/index.html\" rel=\"noopener noreferrer nofollow\"><strong> <u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/index.html<\/u><\/strong><\/a><\/p>\n<p><strong>You will need 2 JavaScript files:<\/strong><\/p>\n<p>To communicate with the Gemini API:<a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/gemini-api.js\" rel=\"noopener noreferrer nofollow\"> <u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/gemini-api.js<\/u><\/a><\/p>\n<p>And<a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/main.js\" rel=\"noopener noreferrer nofollow\"> <u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/main.js<\/u><\/a> To format the output result on the page without reloading the page.<\/p>\n<h4>Change app.py<\/h4>\n<p>Let\u2019s modify our app.py file with the following code:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/989\/24d\/6f0\/98924d6f031ee715ae1eb19d0c37c691.png\" width=\"1360\" height=\"731\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/989\/24d\/6f0\/98924d6f031ee715ae1eb19d0c37c691.png\"\/><\/figure>\n<p>You can copy the code from here: <a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/app.py\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/app.py<\/u><\/a><\/p>\n<p>Once you are ready, run this command in the project folder:<\/p>\n<p><code>python3 app.py<\/code><\/p>\n<p>If you did everything correctly, you will be able to see your ChatBot.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2a1\/0fd\/636\/2a10fd63613afa77ecd7f368cf55e658.png\" width=\"1360\" height=\"731\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2a1\/0fd\/636\/2a10fd63613afa77ecd7f368cf55e658.png\"\/><\/figure>\n<h3>Conclusion<\/h3>\n<p>As you can see, building a chatbot with Python and the Gemini API is not that difficult. You can further improve it by adding styles, extra functions, or even vision recognition. If you run into any issues, feel free to leave a comment explaining your problem, and I&#8217;ll try to help you.<\/p>\n<p>Cheers! \ud83d\ude42<\/p>\n<\/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\/820729\/\"> https:\/\/habr.com\/ru\/articles\/820729\/<\/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>In this article, we are going to do something really cool: we will build a chatbot using Python and the Gemini API. This will be a web-based assistant and could be the beginning of your own AI project. It&#8217;s beginner-friendly, and I will guide you through it step-by-step. By the end, you&#8217;ll have your own AI assistant!<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6667010aaeb5569d7b91442e\" data-style=\"\" id=\"6667010aaeb5569d7b91442e\" width=\"\"><\/div>\n<p><a href=\"https:\/\/www.youtube.com\/@proflead\/videos?sub_confirmation=1\" rel=\"noopener noreferrer nofollow\">Visit my YouTube Channel<\/a><\/p>\n<h3>What You&#8217;ll Need<\/h3>\n<ul>\n<li>\n<p>IDE (I recommend Visual Studio Code)<\/p>\n<\/li>\n<li>\n<p>Gemini API key<\/p>\n<\/li>\n<li>\n<p>Python<\/p>\n<\/li>\n<li>\n<p>Python libraries<\/p>\n<\/li>\n<\/ul>\n<h3>Download IDE &#8212; VS code<\/h3>\n<p>You can use any IDE you like, but if you don\u2019t have one, please download VS Code. It\u2019s really powerful and easy to use. Here&#8217;s the link:\u00a0 <a href=\"https:\/\/code.visualstudio.com\/download\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/code.visualstudio.com\/download<\/u><\/a><\/p>\n<figure class=\"full-width\">\n<div><figcaption>Download IDE &#8212; VS code<\/figcaption><\/div>\n<\/figure>\n<h3>Gemini API<\/h3>\n<h4>Create a Google Cloud Project<\/h4>\n<p>Before we obtain an API key, we need to create a project in Google Cloud. To create a project, please follow this link: <a href=\"https:\/\/console.cloud.google.com\/cloud-resource-manager\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/console.cloud.google.com\/cloud-resource-manager<\/u><\/a>\u00a0<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Create a Google Cloud Project<\/figcaption><\/div>\n<\/figure>\n<p>After the project is created, we are ready to request an API key.<\/p>\n<h4>How to Get Gemini API Key<\/h4>\n<p>To get the API key, visit<a href=\"https:\/\/aistudio.google.com\/app\/apikey\" rel=\"noopener noreferrer nofollow\"> <u>https:\/\/aistudio.google.com\/app\/apikey<\/u><\/a> and click on the &#171;Create API key&#187; button.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>How to Get Gemini API Key<\/figcaption><\/div>\n<\/figure>\n<p>Then, select the project that you created in the previous step from the drop-down menu and click &#171;Generate API key\u201d.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>How to Get Gemini API Key<\/figcaption><\/div>\n<\/figure>\n<p>Copy the key; we\u2019ll need it in the next steps.<\/p>\n<h3>Install Python<\/h3>\n<p><strong>Windows:<\/strong> Download the installer from <a href=\"https:\/\/www.python.org\/downloads\/windows\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.python.org\/downloads\/windows\/<\/u><\/a><\/p>\n<figure class=\"full-width\">\n<div><figcaption>Install Python<\/figcaption><\/div>\n<\/figure>\n<p><strong>Linux (Ubuntu\/Debian):<\/strong>\u00a0Use this command in your terminal window:<\/p>\n<p><code>sudo apt-get install python3<\/code><\/p>\n<figure class=\"full-width\">\n<div><figcaption>Linux (Ubuntu\/Debian)<\/figcaption><\/div>\n<\/figure>\n<h3>Install Python Libraries<\/h3>\n<p>For the next steps, you need to use the terminal. If you are on Windows, you can use <a href=\"https:\/\/apps.microsoft.com\/detail\/9n0dx20hk701?rtc=1&amp;hl=en-us\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/apps.microsoft.com\/detail\/9n0dx20hk701?rtc=1&amp;hl=en-us<\/u><\/a> <\/p>\n<h4>Install PIP<\/h4>\n<p>After we set up Python, we need to set up the pip package installer for Python.<\/p>\n<p><code>sudo apt install python3-pip<\/code><\/p>\n<figure class=\"full-width\">\n<div><figcaption>Install PIP<\/figcaption><\/div>\n<\/figure>\n<h4>Set Up a Virtual Environment<\/h4>\n<p>The next step is to set up virtual environments for our project to manage dependencies separately.<\/p>\n<p>Use this command:<\/p>\n<p><code>sudo apt install python3-venv<\/code>\u00a0<\/p>\n<p>The command python3 -m venv myprojectenv is used to create a virtual environment for a Python project:<\/p>\n<p><code>python3 -m venv myprojectenv<\/code><\/p>\n<p>The command source myprojectenv\/bin\/activate is used to activate the virtual environment:<\/p>\n<p><code>source myprojectenv\/bin\/activate<\/code><\/p>\n<h4>Install LangChain<\/h4>\n<p>LangChain is a framework designed to simplify the creation of applications using large language models.<\/p>\n<p>Use this command:<\/p>\n<p><code>pip install langchain-core<\/code><\/p>\n<h4>Install LangChain-Google-GenAI<\/h4>\n<p>Use this command:<\/p>\n<p><code>pip install langchain-google-genai<\/code><\/p>\n<p>This package contains the LangChain integrations for Gemini through their generative-ai SDK.<\/p>\n<p>Once you\u2019ve done that, we are ready to go to the next steps.<\/p>\n<h4>Install Flask<\/h4>\n<p>Once the virtual environment is activated, we can use pip to set up Flask.<\/p>\n<p>Use this command:<\/p>\n<p><code>pip install Flask<\/code><\/p>\n<h3>Create a ChatBot with the Python Flask Framework<\/h3>\n<p>First, let\u2019s create a directory for our app.<\/p>\n<p>Use these commands:<\/p>\n<p><code>mkdir myflaskapp<\/code><\/p>\n<p><code>cd myflaskapp<\/code><\/p>\n<p>Inside the directory, create a file for our app and call it &#171;app.py&#187;.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Create a ChatBot with the Python Flask Framework<\/figcaption><\/div>\n<\/figure>\n<p>Then add the following content:<\/p>\n<p><code>from flask import Flask<\/code><\/p>\n<p><code>app = Flask(name)<\/code><\/p>\n<p><code><a class=\"mention\" href=\"\/users\/app\">@app<\/a>.route('\/')<\/code><\/p>\n<p><code>def home():<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0return \"Hello, Flask!\"<\/code><\/p>\n<p><code>if name == 'main':<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0app.run(debug=True)<\/code><\/p>\n<p>To make sure that our app is working fine, let\u2019s run it.<\/p>\n<p>Use this command:<\/p>\n<p><code>python3 app.py<\/code><\/p>\n<p>If everything is okay, you will be able to access your Flask app at http:\/\/<u>127.0.0.1:5000<\/u>.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h4>Create an HTML Page for the Flask App<\/h4>\n<p>You can create your own HTML or use the example provided.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>You can download it from here:<a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/index.html\" rel=\"noopener noreferrer nofollow\"><strong> <u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/index.html<\/u><\/strong><\/a><\/p>\n<p><strong>You will need 2 JavaScript files:<\/strong><\/p>\n<p>To communicate with the Gemini API:<a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/gemini-api.js\" rel=\"noopener noreferrer nofollow\"> <u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/gemini-api.js<\/u><\/a><\/p>\n<p>And<a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/main.js\" rel=\"noopener noreferrer nofollow\"> <u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/web\/main.js<\/u><\/a> To format the output result on the page without reloading the page.<\/p>\n<h4>Change app.py<\/h4>\n<p>Let\u2019s modify our app.py file with the following code:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>You can copy the code from here: <a href=\"https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/app.py\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/github.com\/proflead\/gemini-flask-app\/blob\/master\/app.py<\/u><\/a><\/p>\n<p>Once you are ready, run this command in the project folder:<\/p>\n<p><code>python3 app.py<\/code><\/p>\n<p>If you did everything correctly, you will be able to see your ChatBot.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>Conclusion<\/h3>\n<p>As you can see, building a chatbot with Python and the Gemini API is not that difficult. You can further improve it by adding styles, extra functions, or even vision recognition. If you run into any issues, feel free to leave a comment explaining your problem, and I&#8217;ll try to help you.<\/p>\n<p>Cheers! \ud83d\ude42<\/p>\n<\/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\/820729\/\"> https:\/\/habr.com\/ru\/articles\/820729\/<\/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-378556","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378556","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=378556"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378556\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}