{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "DhLp-vDTjInB", "outputId": "d40b1ff3-1fca-4dab-fb76-25a66abdce2d" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collecting langchain_openai\n", " Downloading langchain_openai-0.3.28-py3-none-any.whl.metadata (2.3 kB)\n", "Requirement already satisfied: pydantic in /usr/local/lib/python3.11/dist-packages (2.11.7)\n", "Requirement already satisfied: langchain-core<1.0.0,>=0.3.68 in /usr/local/lib/python3.11/dist-packages (from langchain_openai) (0.3.70)\n", "Requirement already satisfied: openai<2.0.0,>=1.86.0 in /usr/local/lib/python3.11/dist-packages (from langchain_openai) (1.97.0)\n", "Requirement already satisfied: tiktoken<1,>=0.7 in /usr/local/lib/python3.11/dist-packages (from langchain_openai) (0.9.0)\n", "Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic) (2.33.2)\n", "Requirement already satisfied: typing-extensions>=4.12.2 in /usr/local/lib/python3.11/dist-packages (from pydantic) (4.14.1)\n", "Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic) (0.4.1)\n", "Requirement already satisfied: langsmith>=0.3.45 in /usr/local/lib/python3.11/dist-packages (from langchain-core<1.0.0,>=0.3.68->langchain_openai) (0.4.8)\n", "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in /usr/local/lib/python3.11/dist-packages (from langchain-core<1.0.0,>=0.3.68->langchain_openai) (8.5.0)\n", "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /usr/local/lib/python3.11/dist-packages (from langchain-core<1.0.0,>=0.3.68->langchain_openai) (1.33)\n", "Requirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.11/dist-packages (from langchain-core<1.0.0,>=0.3.68->langchain_openai) (6.0.2)\n", "Requirement already satisfied: packaging>=23.2 in /usr/local/lib/python3.11/dist-packages (from langchain-core<1.0.0,>=0.3.68->langchain_openai) (25.0)\n", "Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.11/dist-packages (from openai<2.0.0,>=1.86.0->langchain_openai) (4.9.0)\n", "Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.11/dist-packages (from openai<2.0.0,>=1.86.0->langchain_openai) (1.9.0)\n", "Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.11/dist-packages (from openai<2.0.0,>=1.86.0->langchain_openai) (0.28.1)\n", "Requirement already satisfied: jiter<1,>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from openai<2.0.0,>=1.86.0->langchain_openai) (0.10.0)\n", "Requirement already satisfied: sniffio in /usr/local/lib/python3.11/dist-packages (from openai<2.0.0,>=1.86.0->langchain_openai) (1.3.1)\n", "Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.11/dist-packages (from openai<2.0.0,>=1.86.0->langchain_openai) (4.67.1)\n", "Requirement already satisfied: regex>=2022.1.18 in /usr/local/lib/python3.11/dist-packages (from tiktoken<1,>=0.7->langchain_openai) (2024.11.6)\n", "Requirement already satisfied: requests>=2.26.0 in /usr/local/lib/python3.11/dist-packages (from tiktoken<1,>=0.7->langchain_openai) (2.32.3)\n", "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.11/dist-packages (from anyio<5,>=3.5.0->openai<2.0.0,>=1.86.0->langchain_openai) (3.10)\n", "Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.23.0->openai<2.0.0,>=1.86.0->langchain_openai) (2025.7.14)\n", "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.23.0->openai<2.0.0,>=1.86.0->langchain_openai) (1.0.9)\n", "Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai<2.0.0,>=1.86.0->langchain_openai) (0.16.0)\n", "Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.11/dist-packages (from jsonpatch<2.0,>=1.33->langchain-core<1.0.0,>=0.3.68->langchain_openai) (3.0.0)\n", "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /usr/local/lib/python3.11/dist-packages (from langsmith>=0.3.45->langchain-core<1.0.0,>=0.3.68->langchain_openai) (3.11.0)\n", "Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in /usr/local/lib/python3.11/dist-packages (from langsmith>=0.3.45->langchain-core<1.0.0,>=0.3.68->langchain_openai) (1.0.0)\n", "Requirement already satisfied: zstandard<0.24.0,>=0.23.0 in /usr/local/lib/python3.11/dist-packages (from langsmith>=0.3.45->langchain-core<1.0.0,>=0.3.68->langchain_openai) (0.23.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.26.0->tiktoken<1,>=0.7->langchain_openai) (3.4.2)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.26.0->tiktoken<1,>=0.7->langchain_openai) (2.5.0)\n", "Downloading langchain_openai-0.3.28-py3-none-any.whl (70 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.6/70.6 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: langchain_openai\n", "Successfully installed langchain_openai-0.3.28\n" ] } ], "source": [ "!pip install langchain_openai pydantic" ] }, { "cell_type": "code", "source": [ "\n", "import os\n", "from google.colab import userdata\n", "os.environ['OPENAI_API_KEY'] = userdata.get('OPENAI_API_KEY')" ], "metadata": { "id": "99ziBbITkabx" }, "execution_count": 3, "outputs": [] }, { "cell_type": "code", "source": [ "from langchain_openai import ChatOpenAI\n", "llm_gpt = ChatOpenAI(\n", " model=\"gpt-4o-mini\",\n", " temperature=0,\n", ")" ], "metadata": { "id": "-IVrdTb2kPm3" }, "execution_count": 4, "outputs": [] }, { "cell_type": "code", "source": [ "import pandas as pd\n", "df= pd.read_csv('/content/captioned_dataset_full.csv' )\n", "df.drop(columns=['Unnamed: 0.1'],inplace=True)\n", "df" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 635 }, "id": "NEfkLf43kXcb", "outputId": "7881edf9-d281-4087-ff95-57d2b85445ca" }, "execution_count": 10, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " attached_carousel_media_urls attached_media_content \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN \n", "... ... ... \n", "3232 NaN NaN \n", "3233 NaN NaN \n", "3234 NaN NaN \n", "3235 NaN NaN \n", "3236 NaN NaN \n", "\n", " attached_media_display_url \\\n", "0 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "1 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "2 https://instagram.fiev22-1.fna.fbcdn.net/v/t51... \n", "3 https://instagram.fiev22-1.fna.fbcdn.net/v/t51... \n", "4 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "... ... \n", "3232 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "3233 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "3234 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "3235 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "3236 https://instagram.fiev22-2.fna.fbcdn.net/v/t51... \n", "\n", " attached_media_display_url_s3 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "3232 NaN \n", "3233 NaN \n", "3234 NaN \n", "3235 NaN \n", "3236 NaN \n", "\n", " attached_media_tagged_users \\\n", "0 ['adars_fpv', 'dino.exc', 'itsmegauchan', 'pah... \n", "1 ['ilive_nepal'] \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "3232 NaN \n", "3233 NaN \n", "3234 NaN \n", "3235 ['citroennepal', 'leapmotor_nepal', 'nissan_ne... \n", "3236 NaN \n", "\n", " attached_video_url clickable_urls \\\n", "0 https://instagram.fiev22-1.fna.fbcdn.net/o1/v/... NaN \n", "1 https://instagram.fiev22-2.fna.fbcdn.net/o1/v/... NaN \n", "2 https://instagram.fiev22-2.fna.fbcdn.net/o1/v/... NaN \n", "3 https://instagram.fiev22-2.fna.fbcdn.net/o1/v/... NaN \n", "4 https://instagram.fiev22-1.fna.fbcdn.net/o1/v/... NaN \n", "... ... ... \n", "3232 https://instagram.fiev22-1.fna.fbcdn.net/o1/v/... NaN \n", "3233 https://instagram.fiev22-2.fna.fbcdn.net/o1/v/... NaN \n", "3234 https://instagram.fiev22-2.fna.fbcdn.net/o1/v/... NaN \n", "3235 https://instagram.fiev22-1.fna.fbcdn.net/o1/v/... NaN \n", "3236 https://instagram.fiev22-1.fna.fbcdn.net/o1/v/... NaN \n", "\n", " coauthor_producers comments_count \\\n", "0 ['adars_fpv'] 5.0 \n", "1 NaN 14.0 \n", "2 NaN 3.0 \n", "3 NaN 34.0 \n", "4 NaN 12.0 \n", "... ... ... \n", "3232 NaN 4.0 \n", "3233 NaN 4.0 \n", "3234 NaN 4.0 \n", "3235 ['omodajaecoo.nepal', 'zeekrnepal', 'leapmotor... NaN \n", "3236 NaN 2.0 \n", "\n", " created_time ... region_location place_name.1 street.1 \\\n", "0 2023-01-28 18:06:17 ... NaN NaN NaN NaN \n", "1 2023-03-04 12:00:32 ... NaN NaN NaN NaN \n", "2 2023-03-06 12:39:36 ... NaN NaN NaN NaN \n", "3 2023-03-25 22:56:36 ... NaN NaN NaN NaN \n", "4 2023-04-03 17:53:20 ... NaN NaN NaN NaN \n", "... ... ... ... .. ... ... \n", "3232 2025-02-02 17:00:00 ... NaN NaN NaN NaN \n", "3233 2025-02-16 17:00:55 ... NaN NaN NaN NaN \n", "3234 2025-02-24 17:13:55 ... NaN NaN NaN NaN \n", "3235 2025-03-28 08:28:26 ... NaN NaN NaN NaN \n", "3236 2025-03-30 17:00:00 ... NaN NaN NaN NaN \n", "\n", " ward.1 city.1 district.1 province.1 country.1 country_code.1 \n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "... ... ... ... ... ... ... \n", "3232 NaN NaN NaN NaN NaN NaN \n", "3233 NaN NaN NaN NaN NaN NaN \n", "3234 NaN NaN NaN NaN NaN NaN \n", "3235 NaN NaN NaN NaN NaN NaN \n", "3236 NaN NaN NaN NaN NaN NaN \n", "\n", "[3237 rows x 79 columns]" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
attached_carousel_media_urlsattached_media_contentattached_media_display_urlattached_media_display_url_s3attached_media_tagged_usersattached_video_urlclickable_urlscoauthor_producerscomments_countcreated_time...region_locationplace_name.1street.1ward.1city.1district.1province.1country.1country_code.1
0NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaN['adars_fpv', 'dino.exc', 'itsmegauchan', 'pah...https://instagram.fiev22-1.fna.fbcdn.net/o1/v/...NaN['adars_fpv']5.02023-01-28 18:06:17...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaN['ilive_nepal']https://instagram.fiev22-2.fna.fbcdn.net/o1/v/...NaNNaN14.02023-03-04 12:00:32...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2NaNNaNhttps://instagram.fiev22-1.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/o1/v/...NaNNaN3.02023-03-06 12:39:36...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3NaNNaNhttps://instagram.fiev22-1.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/o1/v/...NaNNaN34.02023-03-25 22:56:36...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-1.fna.fbcdn.net/o1/v/...NaNNaN12.02023-04-03 17:53:20...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
..................................................................
3232NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-1.fna.fbcdn.net/o1/v/...NaNNaN4.02025-02-02 17:00:00...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3233NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/o1/v/...NaNNaN4.02025-02-16 17:00:55...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3234NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/o1/v/...NaNNaN4.02025-02-24 17:13:55...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3235NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaN['citroennepal', 'leapmotor_nepal', 'nissan_ne...https://instagram.fiev22-1.fna.fbcdn.net/o1/v/...NaN['omodajaecoo.nepal', 'zeekrnepal', 'leapmotor...NaN2025-03-28 08:28:26...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3236NaNNaNhttps://instagram.fiev22-2.fna.fbcdn.net/v/t51...NaNNaNhttps://instagram.fiev22-1.fna.fbcdn.net/o1/v/...NaNNaN2.02025-03-30 17:00:00...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "

3237 rows × 79 columns

\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df" } }, "metadata": {}, "execution_count": 10 } ] }, { "cell_type": "code", "source": [ "list(df['owner_username'].unique())" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "1rEZH0RktLr4", "outputId": "2247731e-9992-457c-a8a3-958405cbc201" }, "execution_count": 45, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['brocadeofficial',\n", " 'adars_fpv',\n", " 'the_levitator',\n", " 'garudx.fpv',\n", " 'lalitpurcityfootballclub',\n", " 'shrijanshresthaa',\n", " 'blacksheepfpv',\n", " 'ur_shoaib',\n", " 'ajaytm43',\n", " 'thehybriddesigner.np',\n", " 'anishakafle',\n", " 'divyadhakal_',\n", " 'roshaan.g',\n", " 'unicefsouthasia',\n", " 'bhawanaraut1',\n", " 'get_nepal',\n", " 'columbianepal',\n", " 'withbibek',\n", " 'diwasg',\n", " 'haitentertainment',\n", " 'octaveeventss',\n", " 'rvl.tv',\n", " 'ruslanstudionepal',\n", " 'ashishflute_official',\n", " 'michaelwumusic',\n", " 'mandygamma',\n", " 'enspace.np',\n", " 'digixel.inc',\n", " 'underadar_official',\n", " 'sahatkasa',\n", " 'eatgrubfood',\n", " 'food_explorer_life',\n", " 'kaffacafe_by_sukunda',\n", " 'ggkaam',\n", " 'gracebhattarai',\n", " 'ufo_nepal',\n", " 'iam_s.i.d.d_',\n", " 'sumitraut._',\n", " 'lowenbeauty',\n", " 'lamuse.np',\n", " 'phoebe_bhattarai',\n", " 'imsurakshyakc',\n", " 'vaishaali_',\n", " 'chamsbro_erawan',\n", " 'istu_karki',\n", " 'brillarenepal',\n", " 'team.nftp',\n", " 'jholeyism',\n", " 'youngbluesss',\n", " 'younglion888',\n", " 'ashimneu',\n", " 'newjalshrestha',\n", " 'sunflower.weekender',\n", " '_jenishm',\n", " 'swtalmbu',\n", " 'mrbvlog2.0',\n", " 'motoworld.np',\n", " 'bijyayy',\n", " 'newstyle_fashionwear_official',\n", " 'munachiya',\n", " 'flightsgyaninepal',\n", " 'buddhaland_co',\n", " 'highgroundnepal',\n", " 's.traveller_nextdoor',\n", " nan,\n", " 'mydarlingfood',\n", " 'riyasthaa',\n", " 'uptrendly.creators',\n", " 'nepal.food',\n", " 'mahindranepal_agnigroup',\n", " '_thehappyhikers_',\n", " 'hyderabadidumbiryani.nepal',\n", " 'nnzeella_shrestha',\n", " 'manify.np',\n", " 'sareeshashrestha',\n", " 'aryan_g.r.g',\n", " 'rtw.np',\n", " '_prabha__gurung_',\n", " 'nepartist',\n", " 'mamitapun',\n", " '_sunny_magar_',\n", " 'pramuditaaudas',\n", " 'orabelle.np',\n", " 'mishisacosmetics',\n", " 'hree_store',\n", " 'cliaraessentialoil_np',\n", " 'muscles_lab',\n", " 'rabindra_dhant1',\n", " 'teks.fitness',\n", " 'diwizpiyalama',\n", " 'locknroll.mma',\n", " 'nepalwarriorschampionship',\n", " 'bjj_asia',\n", " 'onechampionship',\n", " 'paradygmsportsnetwork',\n", " 'latidonepal',\n", " 'grappleasiapod',\n", " 'somafightclub',\n", " 'razee.maharjan',\n", " 'razeechan',\n", " '_anupchau',\n", " 'shrishes_mdr',\n", " 'ideapreneurnepal',\n", " 'sanjogkoirala_',\n", " 'shreepaisaofficial',\n", " 'sushant_pradhan_',\n", " 'hemantabhandari_',\n", " 'usembassynepal',\n", " 'foodmandu',\n", " 'thismorninglive',\n", " 'asifshah_nepal',\n", " 'sahikura_',\n", " 'entrepreneur_nepal',\n", " 'kathmandu_locals',\n", " 'colgatenepal',\n", " 'siddinathapa',\n", " 'sjpoon_official',\n", " '_me_supriya',\n", " '_its.me.muskan_',\n", " 'tashyilha_g',\n", " 'instaa.goddess',\n", " 'cubex.clo',\n", " 'newmew.nepal',\n", " 'koreankini',\n", " 'samirstha319',\n", " 'pubgm.np.official',\n", " '_richa.s',\n", " 'buwb.pod',\n", " 'chankheyproduction',\n", " 'openhousepkr',\n", " '_contentsby.richa']" ] }, "metadata": {}, "execution_count": 45 } ] }, { "cell_type": "code", "source": [ " query = 'How many likes have divya dhakal got while promoting BYD'\n", " prompt = f'''Given a pandas DataFrame with columns:{list(df.columns)}, usernames:{list(df['owner_username'].unique())}, write pandas code to {query}. Return only valid Python code. Don't return the imports too. Don't even include the **python** keyword in the beginning. Just give me one liner runnable code'''" ], "metadata": { "id": "WZz94osZk9DS" }, "execution_count": 80, "outputs": [] }, { "cell_type": "code", "source": [ "code_response=llm_gpt.invoke(prompt).content\n", "code_response" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "7-xfQ7IvlhR9", "outputId": "145ffaf2-024f-463a-b700-df8e003ef6fe" }, "execution_count": 81, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "\"df[(df['owner_username'] == 'divyadhakal_') & (df['brand_promoted'] == 'BYD')]['likes_count'].sum()\"" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 81 } ] }, { "cell_type": "code", "source": [ "def execute_pandas_query(code_str: str, df: pd.DataFrame):\n", " code = code_str.strip()\n", " print('The code is:', code)\n", " try:\n", " local_vars = {\"df\": df} # Pass your existing DataFrame\n", " result = eval(code_str, {}, local_vars)\n", " print('The result is:', result)\n", " return result\n", "\n", " except Exception as e:\n", " raise RuntimeError(f\"Execution error: {e}\")" ], "metadata": { "id": "YwfKchhbqU_1" }, "execution_count": 82, "outputs": [] }, { "cell_type": "code", "source": [ "# Example use:\n", "count = execute_pandas_query(\n", " code_response,\n", " df\n", ")\n", "print(\"Result:\", count)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "OybMPTs2sEKh", "outputId": "62dd72f5-b39b-460b-a9a9-a21f60bb162c" }, "execution_count": 83, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "The code is: df[(df['owner_username'] == 'divyadhakal_') & (df['brand_promoted'] == 'BYD')]['likes_count'].sum()\n", "The result is: 0.0\n", "Result: 0.0\n" ] } ] }, { "cell_type": "code", "source": [ "df[(df['owner_username'] == 'divyadhakal_') & (df['likes_count'] > 1000)].shape[0]" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "FRVpCf2isHqn", "outputId": "845b25a1-7a9c-471d-9bd9-29a9bdd06897" }, "execution_count": 50, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "159" ] }, "metadata": {}, "execution_count": 50 } ] }, { "cell_type": "code", "source": [ "# Example DataFrame (only if you haven't defined it already)\n", "import pandas as pd\n", "\n", "# Assuming 'df' already exists with correct columns\n", "# If not, here's a dummy example:\n", "# df = pd.DataFrame({'owner_username': ['divyadhakal_'], 'likes_count': [1500]})\n", "\n", "code_str = \"df[(df['owner_username'] == 'divyadhakal_') & (df['likes_count'] > 1000)].shape[0]\"\n", "local_vars = {\"df\": df} # Pass your existing DataFrame\n", "\n", "result = eval(code_str, {}, local_vars)\n", "print(\"Result:\", result)\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Pqn5OHRUsT7P", "outputId": "bf75f028-c567-4824-bb95-293aa1485a10" }, "execution_count": 51, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Result: 159\n" ] } ] }, { "cell_type": "code", "source": [], "metadata": { "id": "mf2ttVert_qz" }, "execution_count": null, "outputs": [] } ] }