<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Github Issue Summarization</title>
  </head>
  <body class="text-center">
    <form class="form-signin" action="summary" method="post">
      <img class="mb-4" src="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png" alt="" width="72" height="72">
      <h1 style="margin-top: -20px;">Github Issue Summarization</h1>
      <p style="margin-left: 20%; margin-right: 20%;">This app takes as input a Github issue body and predicts a title for it. Behind the scenes it uses a
        <a href="https://github.com/tensorflow/tensor2tensor" target="_blank">Tensor2Tensor</a> TensorFlow model, served via <a href="https://github.com/tensorflow/serving/" target="_blank">TF-Serving </a>.</p>
      <p>(Thanks to <a href="https://github.com/hamelsmu" target="_blank">Hamel Husain</a> for the original concept and source data.)</p>
      <p>Enter the body of a github issue or the url of a github issue and click on Submit. The model then tries to generate a title or summary of the issue.</p>
      <h3 class="h3 mb-3 font-weight-normal">Enter Github Issue Body</h3>
      <p><button id="generate_random_issue_button" type="button">Populate Random Issue</button></p>
      <p><textarea id="issue_body_textarea" class="scrollabletextbox" name="issue_text" rows=8 cols=100></textarea></p>
      <h3 class="h3 mb-3 font-weight-normal">OR Enter Github Issue URL</h3>
      <p><input id="issue_url_textarea" name="issue_url" type="text" size="100" placeholder="https://github.com/kubeflow/kubeflow/issues/232"></input></p>
      <p><button id="submit" type="button">Generate Title</button></p>
    </form>
    <div id="generated_title_div" style="display: none;">
      <h2>Machine Generated Title</h2>
      <p style="margin-right: 20%; margin-left: 20%;" id="generated_title"></p>
    </div>
    <p style="font-style: italic; margin-right: 20%; margin-left: 20%; margin-top: 40px;" id="generated_title">This demo is run using <a target="_blank" href="https://github.com/kubeflow/kubeflow/">Kubeflow</a> - a machine learning toolkit for Kubernetes. Kubeflow is dedicated to making deployment of machine learning on Kubernetes simple, portable and scalable.</p>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script type="text/javascript">
      $("#generate_random_issue_button").click(function(){
          $.ajax({url: window.location.pathname + "random_github_issue", success: function(result){
              $("#issue_body_textarea").html(result.body);
          }});
      });
      $("#submit").click(function(){
          $("#generated_title").html("");
          var issue_body_textarea = $("#issue_body_textarea").val();
          var issue_url_textarea = $("#issue_url_textarea").val();
          $.post(window.location.pathname + "summary", {issue_text: issue_body_textarea, issue_url: issue_url_textarea}, function(result){
              $("#generated_title").html("“" + result.summary + "”");
              $("#issue_body_textarea").html(result.body);
              $("#generated_title_div").show();

          });
      });
    </script>
  </body>
</html>
