master
/ main.ipynb

main.ipynb @master

af5088c
 
 
 
fea61b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401591c
fea61b0
 
 
 
401591c
fea61b0
 
 
 
 
401591c
fea61b0
 
 
 
 
401591c
fea61b0
 
 
 
 
401591c
fea61b0
 
 
 
 
401591c
fea61b0
 
 
 
 
 
401591c
fea61b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401591c
 
 
 
fea61b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401591c
fea61b0
 
 
 
 
 
401591c
fea61b0
 
 
 
 
401591c
fea61b0
 
 
 
 
 
 
 
af5088c
549e5c8
af5088c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ee792e
 
fea61b0
2ee792e
fea61b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af5088c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ee792e
 
549e5c8
2ee792e
549e5c8
2ee792e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af5088c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "08:08:20 INFO:best_model: ./results/output_poem/best_model/model-61170\n",
      "\n",
      "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n",
      "08:08:20 WARNING:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n",
      "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n",
      "08:08:20 WARNING:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "08:08:20 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n",
      "08:08:20 WARNING:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use standard file APIs to check for files with this prefix.\n",
      "08:08:21 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use standard file APIs to check for files with this prefix.\n"
     ]
    }
   ],
   "source": [
    "# coding: utf-8\n",
    "import os\n",
    "import sys\n",
    "# Define root path\n",
    "sys.path.append('../')\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}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Poetry': '我有被霖浪,是笑君强惩。小道见肩食,墨物不可存。'}\n"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    conf = {\"诗词形式\": '藏头诗', \"四字短语\": '我是小墨', '体裁':'五言'}\n",
    "    aa = handle(conf)\n",
    "    print(aa)\n",
    "#     print(len(aa['Poetry']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding = utf8\n",
    "# You can use other public modules via our Client object with module's identifier\n",
    "# and parameters.\n",
    "# For more detailes, please see our online document - https://momodel.github.io/docs/#\n",
    "\n",
    "import os\n",
    "import sys\n",
    "\n",
    "# Define root path\n",
    "sys.path.append('../')\n",
    "\n",
    "# Import necessary packages\n",
    "from modules import json_parser\n",
    "from modules import Client\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='Untitled.ipynb')\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",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/jovyan/work\n",
      "02:24:31 INFO:best_model: ./results/output_poem/best_model/model-61170\n",
      "\n",
      "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n",
      "02:24:31 WARNING:From /home/jovyan/work/char_rnn_model.py:51: LSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n",
      "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n",
      "02:24:31 WARNING:From /home/jovyan/work/char_rnn_model.py:62: MultiRNNCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "02:24:31 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "WARNING:tensorflow:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n",
      "02:24:31 WARNING:From /home/jovyan/work/char_rnn_model.py:107: static_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `keras.layers.RNN(cell, unroll=True)`, which is equivalent to this API\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use standard file APIs to check for files with this prefix.\n",
      "02:24:31 WARNING:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use standard file APIs to check for files with this prefix.\n",
      "result:\n",
      "大仪非是寇,谁将戚戚中。不足贤良祚,开筵始讽钟。\n"
     ]
    }
   ],
   "source": [
    "from write_poem import start_model\n",
    "\n",
    "path = os.getcwd()  # 获取当前工作目录\n",
    "print(path)\n",
    "writer = start_model()\n",
    "\n",
    "\n",
    "def write_poem():\n",
    "    start_with = '大是大非开始了'\n",
    "    poem_style = 4\n",
    "    if start_with:\n",
    "        if poem_style == 3:\n",
    "            return writer.cangtou(start_with)\n",
    "        elif poem_style == 4:\n",
    "            return writer.hide_words(start_with)\n",
    "\n",
    "    if poem_style == 1:\n",
    "        return writer.free_verse()\n",
    "    elif poem_style == 2:\n",
    "        return writer.rhyme_verse()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    result = write_poem()\n",
    "    print('result:')\n",
    "    print(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "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",
    "\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.py', \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",
    "    # paste your code here\n",
    "    # path = os.getcwd()  # 获取当前工作目录\n",
    "    # print(path)\n",
    "    if conf['style'] == ['藏头诗']:\n",
    "        poetry = writer.cangtou(conf['Chinese_word'])\n",
    "    elif conf['style'] == ['藏字诗']:\n",
    "        poetry = writer.hide_words(conf['Chinese_word'])\n",
    "    else:\n",
    "        poetry = writer.rhyme_verse()\n",
    "    return {\"Poetry\": poetry}\n",
    "\n",
    "\n",
    "# if __name__ == '__main__':\n",
    "#     conf = {\"style\": ['藏头诗'], \"Chinese_word\": '杨赛赛'}\n",
    "#     aa = handle(conf)\n",
    "#     print(aa)\n"
   ]
  }
 ],
 "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
}