{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4219f48f",
   "metadata": {},
   "source": [
    "## Annotate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "8a3808b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "254 podcasts.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>description</th>\n",
       "      <th>tags</th>\n",
       "      <th>latest_episode_url</th>\n",
       "      <th>author_name</th>\n",
       "      <th>author_email</th>\n",
       "      <th>n_episodes</th>\n",
       "      <th>url</th>\n",
       "      <th>rss_url</th>\n",
       "      <th>last_updated</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>37356</td>\n",
       "      <td>Amazing Hope Christian Church International</td>\n",
       "      <td>Welcome to Amazing Hope Christian Church Inter...</td>\n",
       "      <td>religion &amp; spirituality;christianity</td>\n",
       "      <td>https://d3ctxlq1ktw2nl.cloudfront.net/staging/...</td>\n",
       "      <td>Amazing Hope Christian Church International</td>\n",
       "      <td>syjmultimedia@gmail.com</td>\n",
       "      <td>128</td>\n",
       "      <td>www.ahcci.net</td>\n",
       "      <td>https://anchor.fm/s/2736ef30/podcast/rss</td>\n",
       "      <td>2022-02-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>97899</td>\n",
       "      <td>Roadside Chat</td>\n",
       "      <td>Join Aqi Camagong and Yuuki Hori as they engag...</td>\n",
       "      <td>education;self-improvement</td>\n",
       "      <td>https://d3ctxlq1ktw2nl.cloudfront.net/producti...</td>\n",
       "      <td>Roadside Chat</td>\n",
       "      <td>collaborate.roadsidechat@gmail.com</td>\n",
       "      <td>22</td>\n",
       "      <td>https://anchor.fm/roadside-chat</td>\n",
       "      <td>https://anchor.fm/s/f57fc74/podcast/rss</td>\n",
       "      <td>2021-06-03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id                                        title  \\\n",
       "0  37356  Amazing Hope Christian Church International   \n",
       "1  97899                                Roadside Chat   \n",
       "\n",
       "                                         description  \\\n",
       "0  Welcome to Amazing Hope Christian Church Inter...   \n",
       "1  Join Aqi Camagong and Yuuki Hori as they engag...   \n",
       "\n",
       "                                   tags  \\\n",
       "0  religion & spirituality;christianity   \n",
       "1            education;self-improvement   \n",
       "\n",
       "                                  latest_episode_url  \\\n",
       "0  https://d3ctxlq1ktw2nl.cloudfront.net/staging/...   \n",
       "1  https://d3ctxlq1ktw2nl.cloudfront.net/producti...   \n",
       "\n",
       "                                   author_name  \\\n",
       "0  Amazing Hope Christian Church International   \n",
       "1                                Roadside Chat   \n",
       "\n",
       "                         author_email  n_episodes  \\\n",
       "0             syjmultimedia@gmail.com         128   \n",
       "1  collaborate.roadsidechat@gmail.com          22   \n",
       "\n",
       "                               url                                   rss_url  \\\n",
       "0                    www.ahcci.net  https://anchor.fm/s/2736ef30/podcast/rss   \n",
       "1  https://anchor.fm/roadside-chat   https://anchor.fm/s/f57fc74/podcast/rss   \n",
       "\n",
       "  last_updated  \n",
       "0   2022-02-01  \n",
       "1   2021-06-03  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "outreach_df = pd.read_csv(\"tmp/en_ph_list.csv\")\n",
    "print(outreach_df.shape[0], \"podcasts\")\n",
    "outreach_df.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8c7aba10",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from suno_utils.pipeline.labeler import SunoAPIClient\n",
    "\n",
    "with open(\"/home/georg/.secrets/secrets.json\") as f:\n",
    "    SUNO_API_TOKEN = json.load(f)[\"suno_api_token\"]\n",
    "\n",
    "suno_client = SunoAPIClient(token=SUNO_API_TOKEN)   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "1565323b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_task_metadata(uid, audio_url, title, description, url, n_episodes):\n",
    "    return {\n",
    "        \"blocks\": [\n",
    "            {\n",
    "                \"type\": \"audio\",\n",
    "                \"label\": \"Listen to the audio below.\",\n",
    "                \"data\": {\"value\": audio_url},\n",
    "            }, \n",
    "            {\n",
    "                \"type\": \"markdown\",\n",
    "                \"data\": {\n",
    "                    \"value\": f\"(id:{uid})\\n\\n{title}\\n\\n{description}\\n\\n{url}\\n\\nTotal Episodes: {n_episodes}\"\n",
    "                },\n",
    "            }, \n",
    "            {\n",
    "                \"type\": \"radio\",\n",
    "                \"label\": \"The majority of the podcast is.\",\n",
    "                \"data\": {\"key\": \"contentType\"},\n",
    "                \"props\": {\n",
    "                    \"options\": [\n",
    "                        {\"value\": v} \n",
    "                        for v in [\n",
    "                            \"English (Filipino Accent)\", \n",
    "                            \"Filipino\",\n",
    "                            \"Mixed English/Filipino\",\n",
    "                            \"Music\",\n",
    "                            \"Other\",\n",
    "                        ]\n",
    "                    ],\n",
    "                    \"direction\": \"column\",\n",
    "                },\n",
    "            },\n",
    "        ],\n",
    "        \"podcast_id\": uid,\n",
    "    }\n",
    "\n",
    "work_items = [\n",
    "    {\n",
    "        \"metadata\": get_task_metadata(\n",
    "            row[\"id\"], row[\"latest_episode_url\"], row[\"title\"], \n",
    "            row[\"description\"], row[\"url\"], row[\"n_episodes\"],\n",
    "        ),\n",
    "    } \n",
    "    for _, row in outreach_df.iterrows()\n",
    "]\n",
    "\n",
    "task_name = \"PHL Podcasts gmail 2\"\n",
    "work_item_set = suno_client.create_work_item_set(name=task_name)\n",
    "remote_work_items = suno_client.create_work_items(work_items, work_item_set_id=work_item_set.id)\n",
    "with open(\"tmp/{}.json\".format(task_name.lower().replace(\" \", \"_\")), \"w\") as f:\n",
    "    json.dump(remote_work_items, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e113b98a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "750c8bb8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fae2e406",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d8587028",
   "metadata": {},
   "source": [
    "## Assemble output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9702d9ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "outreach_df = pd.read_csv(\"tmp/en_ph_list.csv\")\n",
    "print(outreach_df.shape[0], \"podcasts\")\n",
    "outreach_df.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "41164bc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from suno_utils.pipeline.labeler import SunoAPIClient\n",
    "\n",
    "with open(\"/home/georg/.secrets/secrets.json\") as f:\n",
    "    SUNO_API_TOKEN = json.load(f)[\"suno_api_token\"]\n",
    "\n",
    "suno_client = SunoAPIClient(token=SUNO_API_TOKEN)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8f215a92",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.pipeline.labeler import WorkItemSet\n",
    "# labeled_results = WorkItemSet(\n",
    "#     id=\"b42eec85-253f-4ed8-b4b9-4a9072eab232\", name=\"PHL Podcast Test\", client=suno_client\n",
    "# ).get_results()\n",
    "# labeled_results = WorkItemSet(\n",
    "#     id=\"226ab584-ec50-4e45-9589-4757f9c935a1\", name=\"PHL Podcast gmail\", client=suno_client\n",
    "# ).get_results()\n",
    "labeled_results = WorkItemSet(\n",
    "    id=\"80ce382e-c25f-4683-82ad-62bc90ba1aee\", name=\"PHL Podcast gmail 2\", client=suno_client\n",
    ").get_results()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17d91544",
   "metadata": {},
   "outputs": [],
   "source": [
    "usable_podcast_id = []\n",
    "for work_item in labeled_results[\"workItems\"]:\n",
    "    podcast_id = work_item[\"metadata\"][\"podcast_id\"]\n",
    "    for annotation in work_item[\"assignments\"]:\n",
    "        if annotation[\"data\"].get(\"contentType\") == \"English (Filipino Accent)\":\n",
    "            usable_podcast_id.append(podcast_id)\n",
    "print(len(usable_podcast_id), \"relevant podcasts found\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "002017dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "outreach_df = outreach_df[outreach_df[\"id\"].isin(usable_podcast_id)]\n",
    "outreach_df = outreach_df.reset_index(drop=True)\n",
    "print(outreach_df.shape[0], \"podcasts found\")\n",
    "outreach_df.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4f82ee88",
   "metadata": {},
   "outputs": [],
   "source": [
    "outreach_df.to_csv(\"outreach_en_phl.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d624c87",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "2e6e0062",
   "metadata": {},
   "source": [
    "## deleting queues"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5899bf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from suno_utils.pipeline.labeler import SunoAPIClient\n",
    "\n",
    "with open(\"/home/georg/.secrets/secrets.json\") as f:\n",
    "    SUNO_API_TOKEN = json.load(f)[\"suno_api_token\"]\n",
    "\n",
    "suno_client = SunoAPIClient(token=SUNO_API_TOKEN)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b88e76bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "suno_client.delete_work_item_set(\"7979a7f6-e27f-4c0e-a664-d1c29f32ad3d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eba6b9fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89a39015",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61d1e571",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e0a49ac",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
