diff --git a/examples/json_capabilities/Text_Classification.ipynb b/examples/json_capabilities/Text_Classification.ipynb index e80fe4f24..5cb7f35bc 100644 --- a/examples/json_capabilities/Text_Classification.ipynb +++ b/examples/json_capabilities/Text_Classification.ipynb @@ -3,7 +3,7 @@ { "cell_type": "markdown", "metadata": { - "id": "KLHiTPXNTf2a" + "id": "Tce3stUlHN0L" }, "source": [ "##### Copyright 2024 Google LLC." @@ -11,14 +11,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "cellView": "form", - "id": "oTuT5CsaTigz" + "id": "tuOe1ymfHZPu" }, "outputs": [], "source": [ - "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", @@ -34,64 +34,65 @@ { "cell_type": "markdown", "metadata": { - "id": "sP8PQnz1QrcF" + "id": "qFdPvlXBOdUN" }, "source": [ - "# Gemini API: Text Classification" + "# Gemini API: Text Classification\n", + "\n", + "---\n" ] }, { "cell_type": "markdown", "metadata": { - "id": "bxGr_x3MRA0z" + "id": "MfBg1C5NB3X0" }, "source": [ - "\n", + "
\n", " \n", - "
\n", " Run in Google Colab\n", "
" + "\n" ] }, { "cell_type": "markdown", "metadata": { - "id": "ysy--KfNRrCq" + "id": "xHxb-dlhMIzW" }, "source": [ "You will use the Gemini API to classify what topics are relevant in the text." ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "SmNOGuCRK0xk" + }, + "source": [ + "## Install dependencies" + ] + }, { "cell_type": "code", "execution_count": 1, "metadata": { - "id": "Ne-3gnXqR0hI" + "id": "AQJjzmYgH3sX" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m158.8/158.8 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25h" - ] - } - ], + "outputs": [], "source": [ - "!pip install -U -q google-generativeai" + "!pip install -U -q google-generativeai # Install the Python SDK" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { - "id": "EconMHePQHGw" + "id": "iQSKjF5WH5N9" }, "outputs": [], "source": [ "import google.generativeai as genai\n", - "\n", "import json\n", "from IPython.display import Markdown\n", "from typing_extensions import TypedDict # in python 3.12 replace typing_extensions with typing" @@ -100,32 +101,32 @@ { "cell_type": "markdown", "metadata": { - "id": "eomJzCa6lb90" + "id": "MUXex9ctTuDB" }, "source": [ - "## Configure your API key\n", + "## Set up your API key\n", "\n", - "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example." + "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see the [Authentication](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) quickstart for an example." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { - "id": "v-JZzORUpVR2" + "id": "wltbMJLIIXGk" }, "outputs": [], "source": [ "from google.colab import userdata\n", - "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", "\n", + "GOOGLE_API_KEY = userdata.get(\"GOOGLE_API_KEY\")\n", "genai.configure(api_key=GOOGLE_API_KEY)" ] }, { "cell_type": "markdown", "metadata": { - "id": "kNE5XslpPpT0" + "id": "Gv7pRql-LGGr" }, "source": [ "## Example" @@ -133,30 +134,21 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { - "id": "d7vfQVmt9uUT" + "id": "Ba3pV3hwLKET" }, "outputs": [ { "data": { - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result", - "text/markdown": [ - "## The Power of Sport: A Catalyst for Social Change\n", - "\n", - "Sports have long been a source of entertainment and inspiration, captivating audiences worldwide with their thrilling competitions and captivating narratives. But beyond the cheers and the victories, sports hold a profound power to drive social change. From promoting gender equality to fostering cross-cultural understanding, the impact of sports extends far beyond the playing field.\n", - "\n", - "One of the most significant ways sports can contribute to social change is by challenging societal norms and promoting inclusivity. The rise of female athletes in traditionally male-dominated sports has shattered stereotypes and empowered women to pursue their athletic dreams. Similarly, the increasing visibility of athletes from diverse backgrounds has helped to break down racial and cultural barriers, fostering a more inclusive and equitable society.\n", - "\n", - "Furthermore, sports can serve as a powerful tool for promoting peace and understanding. International sporting events, such as the Olympics, bring together athletes and spectators from all corners of the globe, fostering a sense of unity and shared humanity. These events can transcend political and cultural differences, creating a platform for dialogue and cooperation.\n", - "\n", - "However, the potential of sports to drive social change is not without its challenges. Issues such as discrimination, corruption, and the exploitation of athletes continue to plague the sporting world. It is crucial to address these issues head-on, ensuring that sports remain a force for good and a platform for positive change.\n", - "\n", - "In conclusion, sports hold immense potential to drive social change, promoting inclusivity, fostering peace, and challenging societal norms. By embracing the power of sports and addressing its challenges, we can harness its transformative potential to create a more just and equitable world. As we celebrate the triumphs and the struggles of athletes on the field, let us also recognize the profound impact they have on society as a whole. \n" + "text/markdown": "## The Unifying Power of Sport: A Bridge Across the Digital Divide\n\nSports have always been a powerful force in bringing people together. From the shared thrill of a game-winning shot to the camaraderie of cheering on a team, the universal language of competition transcends cultural boundaries and unites individuals in a common experience. This unifying power of sports is particularly crucial in today's increasingly digital world, where social isolation and digital divides can become isolating forces.\n\nIn a society increasingly reliant on virtual interaction, sports provide a much-needed outlet for real-life connections. Whether it's participating in a local league, attending a community game, or simply discussing the latest sporting news with friends and family, sports offer a tangible way to connect with others and build relationships. This shared experience, often centered around passion and excitement, helps to bridge the digital gap and foster a sense of belonging.\n\nBeyond the social aspect, sports can also serve as a vital tool for combating the negative effects of excessive screen time. Physical activity, a key element of many sports, promotes both mental and physical well-being. Engaging in sports encourages kids to disconnect from their devices and experience the joys of active play, fostering healthy habits and combating sedentary lifestyles. This is especially important in today's digital landscape where children are increasingly bombarded with screens.\n\nFurthermore, sports can help to bridge the educational divide by providing opportunities for mentorship and learning. By participating in sports, children and young adults can learn valuable life lessons such as teamwork, discipline, and perseverance. Sports also offer a platform for role models and mentors, allowing young people to connect with individuals who have achieved success through hard work and dedication. This mentorship can empower and inspire the next generation, regardless of their socioeconomic background or access to technology.\n\nUltimately, the unifying power of sports remains a vital force in navigating the complexities of the digital age. By fostering real-life connections, encouraging physical activity, and providing opportunities for learning and mentorship, sports offer a valuable antidote to the isolating effects of technology and can contribute to a more connected and well-rounded society. \n", + "text/plain": [ + "" ] - } + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -168,9 +160,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": { - "id": "704lXZcS9uUT" + "id": "s6OUVYx5LfJz" }, "outputs": [], "source": [ @@ -193,9 +185,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": { - "id": "LMTjb4Gs9uUU" + "id": "owfUpKKHL0tF" }, "outputs": [ { @@ -204,46 +196,33 @@ "text": [ "{\n", " \"topics\": [\n", - " \"topic\": \"Gender Equality\",\n", - " \"relevance\": 0.6\n", - " },\n", " {\n", - " \"topic\": \"Inclusivity\",\n", - " \"relevance\": 0.6\n", + " \"topic\": \"Sports\",\n", + " \"relevance\": 0.8\n", " },\n", " {\n", - " \"topic\": \"Peace\",\n", - " \"relevance\": 0.5\n", + " \"topic\": \"Social Connection\",\n", + " \"relevance\": 0.7\n", " },\n", " {\n", - " \"topic\": \"Cultural Understanding\",\n", - " \"relevance\": 0.5\n", - " },\n", - " {\n", - " \"topic\": \"Discrimination\",\n", - " \"relevance\": 0.4\n", - " },\n", - " {\n", - " \"topic\": \"Corruption\",\n", - " \"relevance\": 0.4\n", - " },\n", - " {\n", - " \"topic\": \"Exploitation\",\n", - " \"relevance\": 0.4\n", - " \"topic\": \"Health\",\n", + " \"topic\": \"Digital Divide\",\n", " \"relevance\": 0.6\n", " },\n", " {\n", - " \"topic\": \"Community\",\n", + " \"topic\": \"Health\",\n", " \"relevance\": 0.5\n", " },\n", " {\n", - " \"topic\": \"Social Impact\",\n", + " \"topic\": \"Education\",\n", " \"relevance\": 0.4\n", " },\n", " {\n", - " \"topic\": \"Peace and Conflict\",\n", + " \"topic\": \"Technology\",\n", " \"relevance\": 0.3\n", + " },\n", + " {\n", + " \"topic\": \"Mentorship\",\n", + " \"relevance\": 0.2\n", " }\n", " ]\n", "}\n" @@ -257,7 +236,7 @@ { "cell_type": "markdown", "metadata": { - "id": "l3XJbxtv1Htk" + "id": "1ZmEIByML5ZG" }, "source": [ "## Summary\n", @@ -269,6 +248,9 @@ ], "metadata": { "colab": { + "collapsed_sections": [ + "Tce3stUlHN0L" + ], "name": "Text_Classification.ipynb", "toc_visible": true },