diff --git a/testing/Python_post_script.ipynb b/testing/Python_post_script.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..f1c3cad7c89dac26b87f73d4b00ac1c229e94315 --- /dev/null +++ b/testing/Python_post_script.ipynb @@ -0,0 +1,257 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "CAFh4lY1FR3S" + }, + "source": [ + "Python script to send POST request" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5XKBySblIBym" + }, + "source": [ + "Top ten highest grossing films in 2021 so far (US box office):\n", + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "St0eQTpyIkUd" + }, + "source": [ + "NB: Mortal Kombat is a martial-arts thriller film. In trainng dataset, the term martial-arts was not hypenated, so decided not to when creating small testing set." + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "executionInfo": { + "elapsed": 462, + "status": "ok", + "timestamp": 1621483094754, + "user": { + "displayName": "Matthew Ipindamitan", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14Ghfx9T0gQmYjyJnrRC2_JcVk1sVXpNeckv-pW3OGQ=s64", + "userId": "14221568594772652826" + }, + "user_tz": -60 + }, + "id": "Qct-7o_RFb5X" + }, + "outputs": [], + "source": [ + "import requests\n", + "import pandas as pd\n", + "from bs4 import BeautifulSoup as bs" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 343 + }, + "executionInfo": { + "elapsed": 2943, + "status": "ok", + "timestamp": 1621486158365, + "user": { + "displayName": "Matthew Ipindamitan", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14Ghfx9T0gQmYjyJnrRC2_JcVk1sVXpNeckv-pW3OGQ=s64", + "userId": "14221568594772652826" + }, + "user_tz": -60 + }, + "id": "I6V-PU1-F1MR", + "outputId": "ad0c6fea-4bad-4dbb-8de5-1660fb8164a5" + }, + "outputs": [ + { + "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>Title</th>\n", + " <th>Genre</th>\n", + " <th>Wiki Page</th>\n", + " <th>Plot</th>\n", + " <th>Genre Prediction</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>Godzilla vs. Kong</td>\n", + " <td>Monster</td>\n", + " <td>https://en.wikipedia.org/wiki/Godzilla_vs._Kong</td>\n", + " <td>Five years after Godzilla defeated King Ghidor...</td>\n", + " <td>action</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>Raya and the Last Dragon</td>\n", + " <td>Animated Fantasy Action Adventure</td>\n", + " <td>https://en.wikipedia.org/wiki/Raya_and_the_Las...</td>\n", + " <td>The prosperous land of Kumandra is ravaged by ...</td>\n", + " <td>action</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>Tom & Jerry</td>\n", + " <td>live-action animated comedy slapstick</td>\n", + " <td>https://en.wikipedia.org/wiki/Tom_%26_Jerry_(2...</td>\n", + " <td>In Manhattan, Tom Cat, who dreams of becoming ...</td>\n", + " <td>comedy romance</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>Demon Slayer: Kimetsu no Yaiba the Movie: Muge...</td>\n", + " <td>animated dark fantasy period action</td>\n", + " <td>https://en.wikipedia.org/wiki/Demon_Slayer:_Ki...</td>\n", + " <td>Tanjiro Kamado, his demon sister Nezuko, Zenit...</td>\n", + " <td>action thriller</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>Mortal Kombat</td>\n", + " <td>martial art fantasy</td>\n", + " <td>https://en.wikipedia.org/wiki/Mortal_Kombat_(2...</td>\n", + " <td>In 17th-century Japan, Lin Kuei assassins led ...</td>\n", + " <td>action</td>\n", + " </tr>\n", + " <tr>\n", + " <th>5</th>\n", + " <td>Nobody</td>\n", + " <td>action thriller</td>\n", + " <td>https://en.wikipedia.org/wiki/Nobody_(2021_film)</td>\n", + " <td>Hutch Mansell is a seemingly ordinary man; he ...</td>\n", + " <td></td>\n", + " </tr>\n", + " <tr>\n", + " <th>6</th>\n", + " <td>The Marksman</td>\n", + " <td>action thriller</td>\n", + " <td>https://en.wikipedia.org/wiki/The_Marksman_(20...</td>\n", + " <td>Former-United States Marine Corps Scout Sniper...</td>\n", + " <td>drama</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7</th>\n", + " <td>The Little Things</td>\n", + " <td>neo-noir crime thriller</td>\n", + " <td>https://en.wikipedia.org/wiki/The_Little_Thing...</td>\n", + " <td>One night in 1990, a girl drives on a highway,...</td>\n", + " <td>thriller</td>\n", + " </tr>\n", + " <tr>\n", + " <th>8</th>\n", + " <td>Wrath of Man</td>\n", + " <td>action thriller</td>\n", + " <td>https://en.wikipedia.org/wiki/Wrath_of_Man</td>\n", + " <td>Patrick Hill begins work at Fortico Security, ...</td>\n", + " <td>action thriller</td>\n", + " </tr>\n", + " <tr>\n", + " <th>9</th>\n", + " <td>The Unholy</td>\n", + " <td>supernatural horror</td>\n", + " <td>https://en.wikipedia.org/wiki/The_Unholy_(2021...</td>\n", + " <td>The film opens with the execution of a woman a...</td>\n", + " <td>thriller</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " Title ... Genre Prediction\n", + "0 Godzilla vs. Kong ... action\n", + "1 Raya and the Last Dragon ... action\n", + "2 Tom & Jerry ... comedy romance\n", + "3 Demon Slayer: Kimetsu no Yaiba the Movie: Muge... ... action thriller\n", + "4 Mortal Kombat ... action\n", + "5 Nobody ... \n", + "6 The Marksman ... drama\n", + "7 The Little Things ... thriller\n", + "8 Wrath of Man ... action thriller\n", + "9 The Unholy ... thriller\n", + "\n", + "[10 rows x 5 columns]" + ] + }, + "execution_count": 74, + "metadata": { + "tags": [] + }, + "output_type": "execute_result" + } + ], + "source": [ + "post_url=\"http://20.86.144.56/predict\"\n", + "test_set_file= 'testing_dataset.csv'\n", + "\n", + "ten_movies = pd.read_csv(test_set_file, delimiter=\",\")\n", + "\n", + "def post_request(movie_plot):\n", + " return [pred.text.strip() for pred in bs(requests.post(post_url, data={'plot': movie_plot}).text, 'html.parser').find_all('li')]\n", + "\n", + "ten_movies[\"Genre Prediction\"] = [\" \".join(post_request(movie_plot)) for movie_plot in ten_movies['Plot']]\n", + "\n", + "ten_movies\n" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMy/2pz9mg3aZKlse96sLy5", + "collapsed_sections": [], + "name": "Python post script", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}