From 49d05ccb0c99076252ff6cf0a54b057fffadc898 Mon Sep 17 00:00:00 2001 From: Jiri Spilka Date: Thu, 5 Sep 2024 21:24:11 +0200 Subject: [PATCH] Add apify-haystack integration example - analyze vibe of instagram comments --- README.md | 1 + ...haystack_instagram_comments_analysis.ipynb | 457 ++++++++++++++++++ 2 files changed, 458 insertions(+) create mode 100644 notebooks/apify_haystack_instagram_comments_analysis.ipynb diff --git a/README.md b/README.md index f85e7ec..1cd1723 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ For more examples, you may also find our [Blog](https://haystack.deepset.ai/blog | Build quizzes and adventures with Character Codex and llamafile | Open In Colab| | Invoking APIs with `OpenAPITool` | Open In Colab| | Extract and use website content for RAG with Apify | Open In Colab| +| Analyze Your Instagram Comments’ Vibe with Apify and Haystack | Open In Colab| | Conversational RAG using Memory | Open In Colab| | Evaluating RAG Pipelines with EvaluationHarness | Open In Colab| | Cohere for Multilingual QA (Haystack 1.x)| Open In Colab| diff --git a/notebooks/apify_haystack_instagram_comments_analysis.ipynb b/notebooks/apify_haystack_instagram_comments_analysis.ipynb new file mode 100644 index 0000000..4b5f785 --- /dev/null +++ b/notebooks/apify_haystack_instagram_comments_analysis.ipynb @@ -0,0 +1,457 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Analyze Your Instagram Comments’ Vibe with Apify and Haystack\n", + "\n", + "Author: Jiri Spilka ([Apify](https://apify.com/jiri.spilka)) \n", + "Idea: Bilge Yücel ([deepset.ai](https://github.com/bilgeyucel))\n", + "\n", + "Ever wondered if your Instagram posts are truly vibrating among your audience?\n", + "In this tutorial, we'll show you how to use the [Instagram Comment Scraper](https://apify.com/apify/instagram-comment-scraper) Actor to download comments from your instagram post and analyze them using a large language model. All performed within the Haystack ecosystem using the [apify-haystack](https://github.com/apify/apify-haystack/tree/main) integration.\n", + "\n", + "We'll start by using the Actor to download the comments, clean the data with the [DocumentCleaner](https://docs.haystack.deepset.ai/docs/documentcleaner) and then use the [OpenAIGenerator](https://docs.haystack.deepset.ai/docs/openaigenerator) to discover the vibe of the Instagram posts." + ], + "metadata": { + "id": "t1BeKtSo7KzI" + } + }, + { + "cell_type": "markdown", + "source": [ + "# Install dependencies" + ], + "metadata": { + "id": "-7zY6NIsCj_5" + } + }, + { + "cell_type": "code", + "source": [ + "!pip install apify-haystack==0.1.4 haystack-ai" + ], + "metadata": { + "id": "r5AJeMOE1Cou", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "63663073-ccc5-4306-ae18-e2720d937407", + "collapsed": true + }, + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting apify-haystack==0.1.4\n", + " Downloading apify_haystack-0.1.4-py3-none-any.whl.metadata (5.4 kB)\n", + "Collecting haystack-ai\n", + " Downloading haystack_ai-2.5.0-py3-none-any.whl.metadata (13 kB)\n", + "Collecting apify-client<2.0.0,>=1.7.1 (from apify-haystack==0.1.4)\n", + " Downloading apify_client-1.8.0-py3-none-any.whl.metadata (4.2 kB)\n", + "Collecting python-dotenv<2.0.0,>=1.0.1 (from apify-haystack==0.1.4)\n", + " Downloading python_dotenv-1.0.1-py3-none-any.whl.metadata (23 kB)\n", + "Collecting haystack-experimental (from haystack-ai)\n", + " Downloading haystack_experimental-0.1.1-py3-none-any.whl.metadata (6.9 kB)\n", + "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (3.1.4)\n", + "Collecting lazy-imports (from haystack-ai)\n", + " Downloading lazy_imports-0.3.1-py3-none-any.whl.metadata (10 kB)\n", + "Requirement already satisfied: more-itertools in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (10.3.0)\n", + "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (3.3)\n", + "Requirement already satisfied: numpy<2 in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (1.26.4)\n", + "Collecting openai>=1.1.0 (from haystack-ai)\n", + " Downloading openai-1.43.0-py3-none-any.whl.metadata (22 kB)\n", + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (2.1.4)\n", + "Collecting posthog (from haystack-ai)\n", + " Downloading posthog-3.6.3-py2.py3-none-any.whl.metadata (2.0 kB)\n", + "Requirement already satisfied: python-dateutil in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (2.8.2)\n", + "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (6.0.2)\n", + "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (2.32.3)\n", + "Requirement already satisfied: tenacity!=8.4.0 in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (9.0.0)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (4.66.5)\n", + "Requirement already satisfied: typing-extensions>=4.7 in /usr/local/lib/python3.10/dist-packages (from haystack-ai) (4.12.2)\n", + "Collecting apify-shared>=1.1.2 (from apify-client<2.0.0,>=1.7.1->apify-haystack==0.1.4)\n", + " Downloading apify_shared-1.1.2-py3-none-any.whl.metadata (2.5 kB)\n", + "Collecting httpx>=0.25.0 (from apify-client<2.0.0,>=1.7.1->apify-haystack==0.1.4)\n", + " Downloading httpx-0.27.2-py3-none-any.whl.metadata (7.1 kB)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.1.0->haystack-ai) (3.7.1)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->haystack-ai) (1.7.0)\n", + "Collecting jiter<1,>=0.4.0 (from openai>=1.1.0->haystack-ai)\n", + " Downloading jiter-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.6 kB)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.1.0->haystack-ai) (2.8.2)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai>=1.1.0->haystack-ai) (1.3.1)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->haystack-ai) (2.1.5)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->haystack-ai) (2024.1)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->haystack-ai) (2024.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil->haystack-ai) (1.16.0)\n", + "Collecting monotonic>=1.5 (from posthog->haystack-ai)\n", + " Downloading monotonic-1.6-py2.py3-none-any.whl.metadata (1.5 kB)\n", + "Collecting backoff>=1.10.0 (from posthog->haystack-ai)\n", + " Downloading backoff-2.2.1-py3-none-any.whl.metadata (14 kB)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->haystack-ai) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->haystack-ai) (3.8)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->haystack-ai) (2.0.7)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->haystack-ai) (2024.8.30)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai>=1.1.0->haystack-ai) (1.2.2)\n", + "Collecting httpcore==1.* (from httpx>=0.25.0->apify-client<2.0.0,>=1.7.1->apify-haystack==0.1.4)\n", + " Downloading httpcore-1.0.5-py3-none-any.whl.metadata (20 kB)\n", + "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx>=0.25.0->apify-client<2.0.0,>=1.7.1->apify-haystack==0.1.4)\n", + " Downloading h11-0.14.0-py3-none-any.whl.metadata (8.2 kB)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->openai>=1.1.0->haystack-ai) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.20.1 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->openai>=1.1.0->haystack-ai) (2.20.1)\n", + "Downloading apify_haystack-0.1.4-py3-none-any.whl (16 kB)\n", + "Downloading haystack_ai-2.5.0-py3-none-any.whl (351 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m351.5/351.5 kB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading apify_client-1.8.0-py3-none-any.whl (71 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.6/71.6 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading openai-1.43.0-py3-none-any.whl (365 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m365.7/365.7 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading python_dotenv-1.0.1-py3-none-any.whl (19 kB)\n", + "Downloading haystack_experimental-0.1.1-py3-none-any.whl (41 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.8/41.8 kB\u001b[0m \u001b[31m649.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading lazy_imports-0.3.1-py3-none-any.whl (12 kB)\n", + "Downloading posthog-3.6.3-py2.py3-none-any.whl (53 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m825.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading apify_shared-1.1.2-py3-none-any.whl (12 kB)\n", + "Downloading backoff-2.2.1-py3-none-any.whl (15 kB)\n", + "Downloading httpx-0.27.2-py3-none-any.whl (76 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.4/76.4 kB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m3.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading jiter-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (318 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.9/318.9 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading monotonic-1.6-py2.py3-none-any.whl (8.2 kB)\n", + "Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hInstalling collected packages: monotonic, python-dotenv, lazy-imports, jiter, h11, backoff, apify-shared, posthog, httpcore, httpx, openai, apify-client, haystack-experimental, haystack-ai, apify-haystack\n", + "Successfully installed apify-client-1.8.0 apify-haystack-0.1.4 apify-shared-1.1.2 backoff-2.2.1 h11-0.14.0 haystack-ai-2.5.0 haystack-experimental-0.1.1 httpcore-1.0.5 httpx-0.27.2 jiter-0.5.0 lazy-imports-0.3.1 monotonic-1.6 openai-1.43.0 posthog-3.6.3 python-dotenv-1.0.1\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Set up the API keys\n", + "\n", + "You need to have an Apify account and obtain [APIFY_API_TOKEN](https://docs.apify.com/platform/integrations/api).\n", + "\n", + "You also need an OpenAI account and [OPENAI_API_KEY](https://platform.openai.com/docs/quickstart)\n" + ], + "metadata": { + "id": "h6MmIG9K1HkK" + } + }, + { + "cell_type": "code", + "source": [ + "import os\n", + "from getpass import getpass\n", + "\n", + "os.environ[\"APIFY_API_TOKEN\"] = getpass(\"Enter YOUR APIFY_API_TOKEN\")\n", + "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter YOUR OPENAI_API_KEY\")" + ], + "metadata": { + "id": "yiUTwYzP36Yr", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "d79acadc-bd18-44d3-c812-9b40c51d5124" + }, + "execution_count": 2, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter YOUR APIFY_API_TOKEN··········\n", + "Enter YOUR OPENAI_API_KEY··········\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Use the Haystack Pipeline to Orchestrate Instagram Comments Scraper, Comments Cleanup, and Analysis Using LLM\n", + "\n", + "Now, let's decide which post to analyze. We can start with these two posts that might reveal some interesting insights:\n", + "\n", + "- `@tiffintech` on [How to easily keep up with tech?](https://www.instagram.com/p/C_a9jcRuJZZ/)\n", + "- `@kamaharishis` on [Affordable Care Act](https://www.instagram.com/p/C_RgBzogufK)\n", + "\n", + "We'll download the comments using the Instagram Scraper Actor. But first, we need to understand the output format of the Actor.\n", + "\n", + "The output is in the following format:\n", + "```json\n", + "[\n", + " {\n", + " \"text\": \"You've just uncovered the goldmine for me 😍 but I still love your news and updates!\",\n", + " \"timestamp\": \"2024-09-02T16:27:09.000Z\",\n", + " \"ownerUsername\": \"codingmermaid.ai\",\n", + " \"ownerProfilePicUrl\": \"....\",\n", + " \"postUrl\": \"https://www.instagram.com/p/C_a9jcRuJZZ/\"\n", + " },\n", + " {\n", + " \"text\": \"Will check it out🙌\",\n", + " \"timestamp\": \"2024-09-02T16:29:28.000Z\",\n", + " \"ownerUsername\": \"author.parijat\",\n", + " \"postUrl\": \"https://www.instagram.com/p/C_a9jcRuJZZ/\"\n", + " }\n", + "]\n", + "```\n", + "We will convert this JSON to a Haystack Document using the `dataset_mapping_function` as follows" + ], + "metadata": { + "id": "HQzAujMc505k" + } + }, + { + "cell_type": "code", + "source": [ + "from haystack import Document\n", + "\n", + "def dataset_mapping_function(dataset_item: dict) -> Document:\n", + " return Document(content=dataset_item.get(\"text\"), meta={\"ownerUsername\": dataset_item.get(\"ownerUsername\")})" + ], + "metadata": { + "id": "OZ0PAVHI_mhn" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Once we understand the Actor output format and have the `dataset_mapping_function`, we can setup the Haystack component to enable interaction between the Haystack and Apify.\n", + "\n", + "First, we need to provide `actor_id`, `dataset_mapping_function` along with input parameters `run_input`.\n", + "\n", + "We can define the `run_input` in three ways: \n", + "- i) when creating the `ApifyDatasetFromActorCall` class \n", + "- ii) as arguments in a pipeline. \n", + "- iii) as argumennts to the `run()` function when we calling `ApifyDatasetFromActorCall.run()` \n", + "- iv) as a combination of `i)` and `ii)` as shown in this tutorial.\n", + "\n", + "For a detailed description of the input parameters, visit the [Instagram Comments Scraper page](https://apify.com/apify/instagram-comment-scraper).\n", + "\n", + "Let's setup the `ApifyDatasetFromActorCall`" + ], + "metadata": { + "id": "xtFquWflA5kf" + } + }, + { + "cell_type": "code", + "source": [ + "from apify_haystack import ApifyDatasetFromActorCall\n", + "\n", + "document_loader = ApifyDatasetFromActorCall(\n", + " actor_id=\"apify/instagram-comment-scraper\",\n", + " run_input={\"resultsLimit\": 50},\n", + " dataset_mapping_function=dataset_mapping_function,\n", + ")" + ], + "metadata": { + "id": "SUWXxT4y55lH" + }, + "execution_count": 4, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "Next, we'll define a `prompt` for the LLM and connect all the components in the [Pipeline](https://docs.haystack.deepset.ai/docs/pipelines)." + ], + "metadata": { + "id": "BxHbPUipjrvS" + } + }, + { + "cell_type": "code", + "source": [ + "from haystack import Pipeline\n", + "from haystack.components.builders import PromptBuilder\n", + "from haystack.components.generators import OpenAIGenerator\n", + "from haystack.components.preprocessors import DocumentCleaner\n", + "\n", + "prompt = \"\"\"\n", + "Analyze these Instagram comments to determine if the post is generating positive energy, excitement,\n", + "or high engagement. Focus on sentiment, emotional tone, and engagement patterns to conclude if\n", + "the post is 'vibrating' with high energy. Be concise.\"\n", + "\n", + "Context:\n", + "{% for document in documents %}\n", + " {{ document.content }}\n", + "{% endfor %}\n", + "\n", + "Analysis:\n", + "\"\"\"\n", + "\n", + "cleaner = DocumentCleaner(remove_empty_lines=True, remove_extra_whitespaces=True, remove_repeated_substrings=True)\n", + "prompt_builder = PromptBuilder(template=prompt)\n", + "generator = OpenAIGenerator(model=\"gpt-3.5-turbo\")\n", + "\n", + "\n", + "pipe = Pipeline()\n", + "pipe.add_component(\"loader\", document_loader)\n", + "pipe.add_component(\"cleaner\", cleaner)\n", + "pipe.add_component(\"prompt_builder\", prompt_builder)\n", + "pipe.add_component(\"llm\", generator)\n", + "pipe.connect(\"loader\", \"cleaner\")\n", + "pipe.connect(\"cleaner\", \"prompt_builder\")\n", + "pipe.connect(\"prompt_builder\", \"llm\")" + ], + "metadata": { + "id": "gdN7baGrA_lR", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "b73b1217-3082-4da7-c824-b8671eeef78d" + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "\n", + "🚅 Components\n", + " - loader: ApifyDatasetFromActorCall\n", + " - cleaner: DocumentCleaner\n", + " - prompt_builder: PromptBuilder\n", + " - llm: OpenAIGenerator\n", + "🛤️ Connections\n", + " - loader.documents -> cleaner.documents (list[Document])\n", + " - cleaner.documents -> prompt_builder.documents (List[Document])\n", + " - prompt_builder.prompt -> llm.prompt (str)" + ] + }, + "metadata": {}, + "execution_count": 5 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "After that, we can run the pipeline. The execution and analysis will take approximately 30-60 seconds." + ], + "metadata": { + "id": "GxDNZ7LqAsWV" + } + }, + { + "cell_type": "code", + "source": [ + "# \\@tiffintech on How to easily keep up with tech?\n", + "url = \"https://www.instagram.com/p/C_a9jcRuJZZ/\"\n", + "\n", + "res = pipe.run({\"loader\": {\"run_input\": {\"directUrls\": [url]}}})\n", + "res.get(\"llm\", {}).get(\"replies\", [\"No response\"])[0]\n", + "\n" + ], + "metadata": { + "id": "qfaWI6BaAko9", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "25e33c1b-f8b9-4b6d-a3d9-0eb54365b820" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'Overall, the Instagram comments on the post reflect positive energy, excitement, and high engagement. The use of emojis such as 😂, 😍, 🙌, ❤️, and 🔥 indicate enthusiasm and excitement. Many comments express gratitude, appreciation, and eagerness to explore the resources mentioned in the post. There are also interactions between users tagging each other and discussing their interest in the topic, further increasing engagement. Overall, the post seems to be generating high energy and positive vibes from the audience.'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 6 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Now, let's us run the same analysis. This time with the @kamalaharris post" + ], + "metadata": { + "id": "jPfgD939E2TW" + } + }, + { + "cell_type": "code", + "source": [ + "# \\@kamalaharris on Affordable Care Act\n", + "url = \"https://www.instagram.com/p/C_RgBzogufK/\"\n", + "\n", + "res = pipe.run({\"loader\": {\"run_input\": {\"directUrls\": [url]}}})\n", + "res.get(\"llm\", {}).get(\"replies\", [\"No response\"])[0]" + ], + "metadata": { + "id": "mCFb8KZOEkpW", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "f6b61f27-59f6-4898-b202-1838f8fd00f2" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'The comments on this post are highly polarized, with strong opinions expressed on both sides of the political spectrum. There is a mix of negative and positive sentiment, with some users expressing excitement and support for the current administration (e.g., emojis like 💙💙💙💙, Kamala 👏👏) while others criticize past policies and individuals associated with them (e.g., Trump 2024, lack of education). Overall, the engagement on this post is high, with users actively debating and defending their viewpoints. Despite the divisive nature of the comments, the post is generating a high level of energy and engagement.'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 7 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "The analysis shows that the first post about [How to easily keep up with tech?](https://www.instagram.com/p/C_a9jcRuJZZ/) is vibrating with high energy:\n", + "\n", + "*The Instagram comments reveal a strong level of engagement and positive energy. Emojis like 😍, 😂, ❤️, 🙌, and 🔥 are frequently used, indicating excitement and enthusiasm. Commenters express gratitude, excitement, and appreciation for the content. The tone is overwhelmingly positive, supportive, and encouraging, with many users tagging others to share the content. Overall, this post is generating a vibrant and highly engaged response.*\n", + "\n", + "However, the post by `@kamalaharris` on the [Affordable Care Act](https://www.instagram.com/p/C_RgBzogufK) is (not surprisingly) sparking a lot of controversy with negative comments.\n", + "\n", + "*The comments on this post are generating negative energy but with high engagement. There's a strong focus on political opinions, particularly concerning insurance companies, the Affordable Care Act, Trump, and Biden. Many comments express frustration, criticism, and disagreement, with some users discussing party affiliations or support for specific politicians. There are also mentions of misinformation and conspiracy theories. Engagement is high, with numerous comment threads delving into various political issues. Overall, this post is vibrating with intense energy, driven by political opinions, disagreements, and active discussions.*\n", + "\n", + "💡 You might receive slightly different results, as the comments may have changed since the last run" + ], + "metadata": { + "id": "45YxSr6v__fI" + } + } + ] +} \ No newline at end of file