diff --git a/.ipynb_checkpoints/app_spec-checkpoint.yml b/.ipynb_checkpoints/app_spec-checkpoint.yml index e206134..12582e5 100644 --- a/.ipynb_checkpoints/app_spec-checkpoint.yml +++ b/.ipynb_checkpoints/app_spec-checkpoint.yml @@ -1,12 +1,20 @@ input: Chinese_word: - value_type: "str" - description: 请输入四字词语 + description: "\u8BF7\u8F93\u5165\u56DB\u5B57\u8BCD\u8BED" + value_type: str style: - value_type: "str" - value_range: ['藏头诗', '藏字诗'] - description: 选择生成诗句的风格 + description: "\u9009\u62E9\u751F\u6210\u8BD7\u53E5\u7684\u98CE\u683C" + value_range: + - "\u85CF\u5934\u8BD7" + - "\u85CF\u5B57\u8BD7" + value_type: str + '体裁': + description: "选择你想要生成的古诗体裁" + value_range: + - "七言" + - "五言" + value_type: str output: Poetry: - value_type: "str" - description: 输出四句诗词 + description: "\u8F93\u51FA\u4E00\u9996\u8BD7\u8BCD" + value_type: str diff --git a/.ipynb_checkpoints/handler-checkpoint.py b/.ipynb_checkpoints/handler-checkpoint.py index 2426e26..bdacaf7 100644 --- a/.ipynb_checkpoints/handler-checkpoint.py +++ b/.ipynb_checkpoints/handler-checkpoint.py @@ -34,14 +34,28 @@ style = conf['style'] # value_type: str # description: some description Chinese_word = conf['Chinese_word'] # value_type: str # description: some description + ticai = conf['体裁'] + # add your code + if ticai == '七言': + char_len = 32 + else: + char_len = 24 # add your code if style == '藏头诗': - poetry = writer.cangtou(Chinese_word) + poetry_test = writer.cangtou(Chinese_word) + while len(poetry_test) != char_len: + poetry_test = writer.cangtou(Chinese_word) + poetry = poetry_test elif conf['style'] == '藏字诗': - poetry = writer.hide_words(Chinese_word) + poetry_test = writer.hide_words(Chinese_word) + while len(poetry_test) != char_len: + poetry_test = writer.cangtou(Chinese_word) + poetry = poetry_test else: - poetry = writer.rhyme_verse() - + poetry_test = writer.rhyme_verse() + while len(poetry_test) != char_len: + poetry_test = writer.cangtou(Chinese_word) + poetry = poetry_test return {'Poetry': poetry} diff --git a/.ipynb_checkpoints/main-checkpoint.ipynb b/.ipynb_checkpoints/main-checkpoint.ipynb index 95068fa..1bc8308 100644 --- a/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/.ipynb_checkpoints/main-checkpoint.ipynb @@ -4,7 +4,19 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "cannot import name 'json_parser'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\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---> 13\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 14\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 15\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mImportError\u001b[0m: cannot import name 'json_parser'" + ] + } + ], "source": [ "# coding = utf8\n", "# You can use other public modules via our Client object with module's identifier\n", @@ -42,14 +54,62 @@ "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", - "07:26:17 INFO:best_model: /home/jovyan/work/results/output_poem/best_model/model-20390\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" + "大仪非是寇,谁将戚戚中。不足贤良祚,开筵始讽钟。\n" ] } ], @@ -86,7 +146,128 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "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" + ] + }, + { + "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\u001b[0m in \u001b[0;36m\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['style'] # value_type: str # description: some description\n", + " Chinese_word = conf['Chinese_word'] # value_type: str # description: some description\n", + " # add your code\n", + " if style == '藏头诗':\n", + " poetry = writer.cangtou(Chinese_word)\n", + " elif conf['style'] == '藏字诗':\n", + " poetry = writer.hide_words(Chinese_word)\n", + " else:\n", + " poetry = writer.rhyme_verse()\n", + "\n", + " return {'Poetry': poetry}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# if __name__ == '__main__':\n", + "# conf = {\"style\": ['藏头诗'], \"Chinese_word\": '杨赛赛'}\n", + "# aa = handle(conf)\n", + "# print(aa)" + ] } ], "metadata": { diff --git a/app_spec.yml b/app_spec.yml index 3a8e114..12582e5 100644 --- a/app_spec.yml +++ b/app_spec.yml @@ -8,6 +8,12 @@ - "\u85CF\u5934\u8BD7" - "\u85CF\u5B57\u8BD7" value_type: str + '体裁': + description: "选择你想要生成的古诗体裁" + value_range: + - "七言" + - "五言" + value_type: str output: Poetry: description: "\u8F93\u51FA\u4E00\u9996\u8BD7\u8BCD" diff --git a/core.10356 b/core.10356 deleted file mode 100644 index 20183bd..0000000 Binary files a/core.10356 and /dev/null differ diff --git a/core.10546 b/core.10546 deleted file mode 100644 index 81563ca..0000000 Binary files a/core.10546 and /dev/null differ diff --git a/core.10754 b/core.10754 deleted file mode 100644 index 3c3dcc1..0000000 Binary files a/core.10754 and /dev/null differ diff --git a/core.11237 b/core.11237 deleted file mode 100644 index bbeb78b..0000000 Binary files a/core.11237 and /dev/null differ diff --git a/core.11826 b/core.11826 deleted file mode 100644 index b214daa..0000000 Binary files a/core.11826 and /dev/null differ diff --git a/handler.py b/handler.py index 2426e26..bdacaf7 100644 --- a/handler.py +++ b/handler.py @@ -34,14 +34,28 @@ style = conf['style'] # value_type: str # description: some description Chinese_word = conf['Chinese_word'] # value_type: str # description: some description + ticai = conf['体裁'] + # add your code + if ticai == '七言': + char_len = 32 + else: + char_len = 24 # add your code if style == '藏头诗': - poetry = writer.cangtou(Chinese_word) + poetry_test = writer.cangtou(Chinese_word) + while len(poetry_test) != char_len: + poetry_test = writer.cangtou(Chinese_word) + poetry = poetry_test elif conf['style'] == '藏字诗': - poetry = writer.hide_words(Chinese_word) + poetry_test = writer.hide_words(Chinese_word) + while len(poetry_test) != char_len: + poetry_test = writer.cangtou(Chinese_word) + poetry = poetry_test else: - poetry = writer.rhyme_verse() - + poetry_test = writer.rhyme_verse() + while len(poetry_test) != char_len: + poetry_test = writer.cangtou(Chinese_word) + poetry = poetry_test return {'Poetry': poetry} diff --git a/main.ipynb b/main.ipynb index 3062ab9..c93075a 100644 --- a/main.ipynb +++ b/main.ipynb @@ -2,7 +2,153 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "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": [ + "05:27:14 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", + "05:27:14 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", + "05:27:14 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", + "05:27:14 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", + "05:27:14 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", + "05:27:15 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": [ + "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", + "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['style'] # value_type: str # description: some description\n", + " ticai = conf['ticai']\n", + " Chinese_word = conf['Chinese_word'] # value_type: str # description: some description\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": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Poetry': '我师当主士,是庆悬林端。小妇买林事,墨山无所传。'}\n" + ] + } + ], + "source": [ + "if __name__ == '__main__':\n", + " conf = {\"style\": '藏头诗', \"Chinese_word\": '我是小墨', 'ticai':'五言'}\n", + " aa = handle(conf)\n", + " print(aa)\n", + "# print(len(aa['Poetry']))" + ] + }, + { + "cell_type": "code", + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -38,9 +184,69 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "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", @@ -119,13 +325,6 @@ "# aa = handle(conf)\n", "# print(aa)\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/project_requirements.txt b/project_requirements.txt index fecd587..521a104 100644 --- a/project_requirements.txt +++ b/project_requirements.txt @@ -1,26 +1,93 @@ -PyWavelets==1.0.2 -cloudpickle==0.8.0 -torchvision==0.2.2.post3 -nltk==3.4 +ipdb==0.13.2 +toolz==0.9.0 +networkx==2.2 +scikit-image==0.14.1 +joblib==0.14.1 +pycparser==2.20 +opencv-contrib-python==4.4.0.42 +et-xmlfile==1.0.1 +appdirs==1.4.4 +retrying==1.3.3 +CairoSVG==2.5.2 +jmespath==0.10.0 pydot==1.4.1 +certipy==0.1.3 +jdcal==1.4.1 +cryptography==3.2.1 +imbalanced-learn==0.6.2 +openpyxl==2.6.4 +filelock==3.0.12 +sacremoses==0.0.45 +tokenizers==0.5.2 +unification==0.2.2 +python-jsonrpc-server==0.0.1 +click==7.1.2 +imgaug==0.2.6 +jieba==0.42.1 +packaging==20.9 +defusedxml==0.7.1 +tf-slim==1.1.0 +word2vec==0.10.6 +calysto==1.0.6 +s3transfer==0.3.3 +configparser==4.0.2 +botocore==1.19.25 +tqdm==4.46.1 +Shapely==1.7.0 +pyOpenSSL==20.0.1 +numpyencoder==0.3.0 +pyrsistent==0.17.3 +oauthlib==3.1.0 +pygame==2.0.1 +gym==0.17.2 +moviepy==1.0.3 +minepy==1.2.4 +imageio==2.8.0 +cssselect2==0.3.0 +sentencepiece==0.1.91 +boto3==1.16.25 +dask==0.20.0 +sympy==1.6.2 +argon2-cffi==20.1.0 +tensorflow-estimator==1.13.0 +torchvision==0.5.0+cpu +regex==2021.4.4 +torch==1.4.0+cpu xlrd==1.2.0 +Augmentor==0.2.8 +Cython==0.29.20 +kanren==0.2.3 +pyenchant==3.1.1 +imageio-ffmpeg==0.4.4 +svgwrite==1.3.1 +distlib==0.3.1 +pytorch-pretrained-bert==0.6.2 +mpmath==1.2.1 +importlib-resources==3.2.1 +PyAudio==0.2.11 +transformers==2.5.1 +pyglet==1.5.0 +baytune==0.3.10 +zipp==1.2.0 +tensorboardX==2.0 +yellowbrick==1.1 +mock==2.0.0 +importlib-metadata==2.1.1 +cairocffi==1.1.0 +metakernel==0.27.5 +multipledispatch==0.6.0 +plotly==4.8.1 +async-generator==1.10 +proglog==0.1.9 +torchtext==0.6.0 +PyWavelets==1.0.1 +cffi==1.14.5 +rouge==1.0.0 +attrs==21.2.0 +func-timeout==4.3.5 +nltk==3.5 +tinycss2==1.0.2 +cloudpickle==0.6.1 jupyterlab-server==0.2.0 -python-jsonrpc-server==0.0.1 -dask==1.1.4 -Shapely==1.6.4.post2 -jieba==0.39 -attrs==19.1.0 -networkx==2.2 -imageio==2.5.0 -tensorflow-estimator==1.13.0 -pyrsistent==0.14.11 -toolz==0.9.0 -torch==1.0.1.post2 -mock==2.0.0 -Cython==0.29.6 -word2vec==0.10.2 -scikit-image==0.14.2 -tqdm==4.31.1 -defusedxml==0.5.0 -singledispatch==3.4.0.3 -imgaug==0.2.8 +minio==5.0.10 +graphviz==0.14