code: def application(environ, start_response):
      """
      WSGI-compatible langid web service.
      """
      try:
          path = shift_path_info(environ)
      except IndexError:
          # Catch shift_path_info's failure to handle empty paths properly
          path = ""
  
      if path == "detect" or path == "rank":
          data = None
  
          # Extract the data component from different access methods
          if environ["REQUEST_METHOD"] == "PUT":
              data = environ["wsgi.input"].read(
                  int(environ["CONTENT_LENGTH"])
              )
          elif environ["REQUEST_METHOD"] == "GET":
              try:
                  data = parse_qs(environ["QUERY_STRING"])["q"][0]
              except KeyError:
                  # No query, provide a null response.
                  status = "200 OK"  # HTTP Status
                  response = {
                      "responseData": None,
                      "responseStatus": 200,
                      "responseDetails": None,
                  }
          elif environ["REQUEST_METHOD"] == "POST":
              input_string = environ["wsgi.input"].read(
                  int(environ["CONTENT_LENGTH"])
              )
              try:
                  data = parse_qs(input_string)["q"][0]
              except KeyError:
                  # No key 'q', process the whole input instead
                  data = input_string
          else:
              # Unsupported method
              status = "405 Method Not Allowed"  # HTTP Status
              response = {
                  "responseData": None,
                  "responseStatus": 405,
                  "responseDetails": "%s not allowed"
                  % environ["REQUEST_METHOD"],
              }
  
          if data is not None:
              if path == "detect":
                  pred, conf = classify(data)
                  responseData = {"language": pred, "confidence": conf}
              elif path == "rank":
                  responseData = rank(data)
  
              status = "200 OK"  # HTTP Status
              response = {
                  "responseData": responseData,
                  "responseStatus": 200,
                  "responseDetails": None,
              }
      elif path == "demo":
          status = "200 OK"  # HTTP Status
          headers = [
              ("Content-type", "text/html; charset=utf-8")
          ]  # HTTP Headers
          start_response(status, headers)
          return [query_form.format(**environ)]
  
      else:
          # Incorrect URL
          status = "404 Not Found"
          response = {
              "responseData": None,
              "responseStatus": 404,
              "responseDetails": "Not found",
          }
  
      headers = [
          ("Content-type", "text/javascript; charset=utf-8")
      ]  # HTTP Headers
      start_response(status, headers)
      return [json.dumps(response)]
  
imports: from __future__ import print_function
  import base64
  import bz2
  import json
  import optparse
  import sys
  import logging
  import numpy
  from wsgiref.simple_server import make_server
  from wsgiref.util import shift_path_info
  from collections import defaultdict
label_desc: Use image node_id 7 for calling a global function with example usage: application(environ, start_response) and returns: list, list