master
/ test.ipynb

test.ipynb @master

3dfba31
 
 
 
401591c
3dfba31
401591c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dfba31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "No module named 'modules'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-739bc8dacedc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;31m# Import necessary packages\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mmodules\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mjson_parser\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      7\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mmodules\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mClient\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      8\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mwrite_poem\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mstart_model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mImportError\u001b[0m: No module named 'modules'"
     ]
    }
   ],
   "source": [
    "# coding: utf-8\n",
    "import os\n",
    "import sys\n",
    "\n",
    "# Import necessary packages\n",
    "from modules import json_parser\n",
    "from modules import Client\n",
    "from write_poem import start_model\n",
    "\n",
    "# Initialise Client object\n",
    "client = Client(api_key='33799e1c5d6fa05fdd7dec3aa7aad868445d1c737edcf9c37fa89cb3b39cb2d9',\n",
    "                project_id='5bfd118f1afd942b66b36b30', user_ID='yangsaisai',\n",
    "                project_type='app', source_file_path='main.ipynb',\n",
    "                silent=True)\n",
    "\n",
    "# Make run/train/predict command alias for further use\n",
    "run = client.run\n",
    "train = client.train\n",
    "predict = client.predict\n",
    "\n",
    "# Make controller alias for further use\n",
    "controller = client.controller\n",
    "writer = start_model()\n",
    "\n",
    "\n",
    "def handle(conf):\n",
    "    \"\"\"\n",
    "    该方法是部署之后,其他人调用你的服务时候的处理方法。\n",
    "    请按规范填写参数结构,这样我们就能替你自动生成配置文件,方便其他人的调用。\n",
    "    范例:\n",
    "    params['key'] = value # value_type: str # description: some description\n",
    "    参数请放到params字典中,我们会自动解析该变量。\n",
    "    \"\"\"\n",
    "\n",
    "    style = conf['诗词形式']  # value_type: str # description: some description\n",
    "    Chinese_word = conf['四字短语']  # value_type: str # description: some description\n",
    "    ticai = conf['体裁']\n",
    "    # add your code\n",
    "    if ticai == '七言':\n",
    "        char_len = 32\n",
    "    else:\n",
    "        char_len = 24\n",
    "    # add your code\n",
    "    if style == '藏头诗':\n",
    "        poetry_test = writer.cangtou(Chinese_word)\n",
    "        while len(poetry_test) != char_len:\n",
    "            poetry_test = writer.cangtou(Chinese_word)\n",
    "        poetry = poetry_test\n",
    "    elif conf['style'] == '藏字诗':\n",
    "        poetry_test = writer.hide_words(Chinese_word)\n",
    "        while len(poetry_test) != char_len:\n",
    "            poetry_test = writer.cangtou(Chinese_word)\n",
    "        poetry = poetry_test\n",
    "    else:\n",
    "        poetry_test = writer.rhyme_verse()\n",
    "        while len(poetry_test) != char_len:\n",
    "            poetry_test = writer.cangtou(Chinese_word)\n",
    "        poetry = poetry_test\n",
    "    return {'Poetry': poetry}"
   ]
  }
 ],
 "metadata": {
  "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}