{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Grover-requester.ipynb",
      "provenance": [],
      "toc_visible": true,
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/mrm8488/shared_colab_notebooks/blob/master/Grover_requester.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_yQD9ClXkXzh",
        "colab_type": "text"
      },
      "source": [
        "# Grover - A State-of-the-Art Defense against Neural Fake News\n",
        "[visit](https://grover.allenai.org/)\n",
        "\n",
        "## COLAB Notebook for requesting Grover's API and generate a fake article based on a headline\n",
        "\n",
        "### By mrm8488@gmail.com"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yz2gsBrEOj8e",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import requests\n",
        "import json\n",
        "\n",
        "url = 'https://api.grover.allenai.org/api/ask'\n",
        "headers = {'Accept': 'application/json, text/plain, */*',\n",
        "           'Referer': 'https://grover.allenai.org/',\n",
        "           'Origin': 'https://grover.allenai.org',\n",
        "           'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36',\n",
        "           'Content-Type': 'application/json;charset=UTF-8'\n",
        "          }"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TZmC9LZMi5NA",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#@title Fake news generator options\n",
        "\n",
        "domain = 'nytimes.com' #@param {type:\"string\"}\n",
        "authors = 'Mark Townsend' #@param {type:\"string\"}\n",
        "date = '2019-07-03' #@param {type:\"date\"}\n",
        "headline = 'Elon Musk in going to close Tesla' #@param {type:\"string\"}\n",
        "#article = '' #@param {type:\"string\"}"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6hnSzTkKLImk",
        "colab_type": "code",
        "outputId": "5a41fe1f-5f0e-470a-d9ff-1930f2a0c489",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 365
        }
      },
      "source": [
        "body = {'target': 'article',\n",
        "       'title': headline,\n",
        "       'article': '',\n",
        "       'domain': domain,\n",
        "       'date': date,\n",
        "       'authors': authors}\n",
        "\n",
        "\n",
        "%time r = requests.post(url, data=json.dumps(body), headers=headers)\n",
        "json_data = json.loads(r.text)\n",
        "print(json_data[\"gen\"])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "CPU times: user 16.6 ms, sys: 5.1 ms, total: 21.7 ms\n",
            "Wall time: 21.1 s\n",
            "Elon Musk has said he is set to close Tesla for a period of 24 hours this month to overhaul his $90 billion company, whose share price plummeted by 16 percent last week in the wake of a bizarre crisis.\n",
            "The electric car maker’s 37-year-old chief executive said that he would take a “leave of absence” as part of his plan to reinvigorate the company he founded 18 years ago.\n",
            "He told staff that the “self-driving revolution will be achieved first on our roads” and promised Tesla would cut corners only when absolutely necessary.\n",
            "“This is going to sound crazy but I want to go home. I want to go to sleep and when I wake up I want to be in this company,” he said in an internal email.\n",
            "“If we can find a really good do-it-yourself version of self-driving, then we should do it first. And then we should do our best to get the commercial version out for our customers.”\n",
            "Tesla’s Palo Alto headquarters was locked down on Thursday as Mr Musk turned up at the plant in the late afternoon. The CEO was reported to have spent three hours meeting Tesla’s production chief, who has been called in from Europe to deal with supply chain troubles.\n",
            "The surge in share price at Tesla came despite the company missing its all-important Model 3 production target in the first half of this year. Analysts said this had put at risk its timeline to turn a profit.\n",
            "Mr Musk became the target of a furious backlash last week when he tweeted “going to take Tesla private at $420”. In a subsequent statement, he offered an explanation for his tweet, which he claimed had been planned “months in advance”.\n",
            "Musk said he was shocked when his tweet on Wednesday triggered a wave of criticism, and he continued to defend his conduct. But he said he felt “compelled to comment and take things back”.\n",
            "“I am almost positive there will be a significant market reaction which will make it worthwhile, and I am confident we can get the proposed price back to shareholders of Tesla at a higher price,” he said.\n",
            "Tesla’s share price has shrunk by more than 30 percent over the past six months amid a wave of profit warnings.\n",
            "At its June level, the share price had valued Tesla at $937 billion. That was roughly a third more than rival car maker, General Motors.\n",
            "Musk has traditionally rebuffed suggestions that he be removed from his role as chief executive. The company is also made up of several subsidiaries, including the SolarCity solar panel maker that Tesla acquired last year.\n",
            "Musk has said repeatedly that the collapse in the share price is a result of investors taking money off the table at the same time as Tesla missed its production targets.\n",
            "His resignation email to staff, said: “Be warned, the self-driving revolution will be achieved first on our roads, and that will require all of us to work hard. Therefore, Tesla will limit overtime, eliminate subsidies on all Tesla products, and cancel all expensive performance variants of all of our vehicles. If that means losing a few Tesla jobs, then so be it.\n",
            "“Only when Tesla can be consistently turned around by the production team can we realise Tesla’s destiny as the world’s greatest automaker.”\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "C9fY8iGoRm3K",
        "colab_type": "text"
      },
      "source": [
        "### Run the cell below to save the generated article to a file"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y38D5KyzRVR1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "f = open(\"fake-article.txt\", \"w\")\n",
        "f.write(json_data[\"gen\"])\n",
        "f.close()"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}