diff --git a/.ipynb_checkpoints/app_spec-checkpoint.yml b/.ipynb_checkpoints/app_spec-checkpoint.yml index 12582e5..a4e8865 100644 --- a/.ipynb_checkpoints/app_spec-checkpoint.yml +++ b/.ipynb_checkpoints/app_spec-checkpoint.yml @@ -8,13 +8,7 @@ - "\u85CF\u5934\u8BD7" - "\u85CF\u5B57\u8BD7" value_type: str - '体裁': - description: "选择你想要生成的古诗体裁" - value_range: - - "七言" - - "五言" - value_type: str output: Poetry: description: "\u8F93\u51FA\u4E00\u9996\u8BD7\u8BCD" - value_type: str + value_type: str \ No newline at end of file diff --git a/.ipynb_checkpoints/handler-checkpoint.py b/.ipynb_checkpoints/handler-checkpoint.py index bdacaf7..f007870 100644 --- a/.ipynb_checkpoints/handler-checkpoint.py +++ b/.ipynb_checkpoints/handler-checkpoint.py @@ -56,10 +56,4 @@ while len(poetry_test) != char_len: poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test - return {'Poetry': poetry} - - -# if __name__ == '__main__': -# conf = {"style": ['藏头诗'], "Chinese_word": '杨赛赛'} -# aa = handle(conf) -# print(aa) \ No newline at end of file + return {'Poetry': poetry} \ No newline at end of file diff --git a/.ipynb_checkpoints/main-checkpoint.ipynb b/.ipynb_checkpoints/main-checkpoint.ipynb index 1bc8308..61d267b 100644 --- a/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/.ipynb_checkpoints/main-checkpoint.ipynb @@ -1,53 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "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", - "# 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, @@ -75,6 +27,188 @@ "name": "stdout", "output_type": "stream", "text": [ + "07:53:48 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", + "07:53:48 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", + "07:53:48 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", + "07:53:48 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", + "07:53:48 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", + "07:53:48 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", @@ -190,83 +324,6 @@ "# 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)" ] } ], diff --git a/Untitled.ipynb b/Untitled.ipynb index 49658ce..d8c39f7 100644 --- a/Untitled.ipynb +++ b/Untitled.ipynb @@ -2,10 +2,142 @@ "cells": [ { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "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": [ + "04:29:29 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", + "04:29:29 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", + "04:29:29 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", + "04:29:29 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", + "04:29:29 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", + "04:29:29 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": [ + "from handler import handle" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "conf = {'体裁':'五言', 'style':'藏头诗', 'Chinese_word':'一二三四'}\n", + "res = handle(conf)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "res1 = res['Poetry'].split('。')[:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "res1 = res['Poetry'].split('。')[:2]\n", + "res2 = []\n", + "for i in res1:\n", + " res2.extend(i.split(','))\n", + "res3 = res2[0]+',\\n'+res2[1]+'。\\n'+res2[2]+',\\n'+res2[3]+'。'" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['一闻江城涯', '二月月涛中', '三湘闇北内', '四海无人同']" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res2" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "一闻江城涯,\n", + "二月月涛中。\n", + "三湘闇北内,\n", + "四海无人同。\n" + ] + } + ], + "source": [ + "res3 = res2[0]+',\\n'+res2[1]+'。\\n'+res2[2]+',\\n'+res2[3]+'。'\n", + "print(res3)" + ] }, { "cell_type": "code", diff --git a/app_spec.yml b/app_spec.yml index 12582e5..a4e8865 100644 --- a/app_spec.yml +++ b/app_spec.yml @@ -8,13 +8,7 @@ - "\u85CF\u5934\u8BD7" - "\u85CF\u5B57\u8BD7" value_type: str - '体裁': - description: "选择你想要生成的古诗体裁" - value_range: - - "七言" - - "五言" - value_type: str output: Poetry: description: "\u8F93\u51FA\u4E00\u9996\u8BD7\u8BCD" - value_type: str + value_type: str \ No newline at end of file diff --git a/handler.py b/handler.py index bdacaf7..dfce570 100644 --- a/handler.py +++ b/handler.py @@ -1,7 +1,8 @@ # coding: utf-8 import os import sys - +# Define root path +sys.path.append('../') # Import necessary packages from modules import json_parser from modules import Client @@ -34,32 +35,31 @@ style = conf['style'] # value_type: str # description: some description Chinese_word = conf['Chinese_word'] # value_type: str # description: some description - ticai = conf['体裁'] + # ticai = conf['体裁'] # add your code - if ticai == '七言': - char_len = 32 - else: - char_len = 24 + # if ticai == '七言': + # char_len = 32 + # else: + # char_len = 24 # add your code if style == '藏头诗': poetry_test = writer.cangtou(Chinese_word) - while len(poetry_test) != char_len: - 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_test = writer.hide_words(Chinese_word) - while len(poetry_test) != char_len: - poetry_test = writer.cangtou(Chinese_word) + # while len(poetry_test) != char_len: + # poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test else: poetry_test = writer.rhyme_verse() - while len(poetry_test) != char_len: - poetry_test = writer.cangtou(Chinese_word) + # while len(poetry_test) != char_len: + # poetry_test = writer.cangtou(Chinese_word) poetry = poetry_test - return {'Poetry': poetry} - - -# if __name__ == '__main__': -# conf = {"style": ['藏头诗'], "Chinese_word": '杨赛赛'} -# aa = handle(conf) -# print(aa) \ No newline at end of file + res1 = poetry.split('。')[:2] + res2 = [] + for i in res1: + res2.extend(i.split(',')) + res3 = res2[0]+',\n'+res2[1]+'。\n'+res2[2]+',\n'+res2[3]+'。' + return {'Poetry': res3} \ No newline at end of file diff --git a/main.ipynb b/main.ipynb index c93075a..fe46df0 100644 --- a/main.ipynb +++ b/main.ipynb @@ -27,48 +27,47 @@ "name": "stdout", "output_type": "stream", "text": [ - "05:27:14 INFO:best_model: ./results/output_poem/best_model/model-61170\n", + "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", - "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", + "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", - "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", + "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", - "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", + "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", - "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", + "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", - "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", + "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", - "\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", @@ -99,9 +98,10 @@ " 参数请放到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", + " 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", @@ -127,20 +127,20 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'Poetry': '我师当主士,是庆悬林端。小妇买林事,墨山无所传。'}\n" + "{'Poetry': '我有被霖浪,是笑君强惩。小道见肩食,墨物不可存。'}\n" ] } ], "source": [ "if __name__ == '__main__':\n", - " conf = {\"style\": '藏头诗', \"Chinese_word\": '我是小墨', 'ticai':'五言'}\n", + " conf = {\"诗词形式\": '藏头诗', \"四字短语\": '我是小墨', '体裁':'五言'}\n", " aa = handle(conf)\n", " print(aa)\n", "# print(len(aa['Poetry']))" diff --git a/project_requirements.txt b/project_requirements.txt index 521a104..f37b604 100644 --- a/project_requirements.txt +++ b/project_requirements.txt @@ -1,93 +1,93 @@ -ipdb==0.13.2 -toolz==0.9.0 -networkx==2.2 +async-generator==1.10 +et-xmlfile==1.0.1 +PyAudio==0.2.11 +cssselect2==0.3.0 +moviepy==1.0.3 +jieba==0.42.1 +pydot==1.4.1 +retrying==1.3.3 scikit-image==0.14.1 +calysto==1.0.6 +torch==1.4.0+cpu +gym==0.17.2 +cffi==1.14.5 +svgwrite==1.3.1 +imbalanced-learn==0.6.2 +PyWavelets==1.0.1 +jdcal==1.4.1 +boto3==1.16.25 +pyglet==1.5.0 +botocore==1.19.25 +oauthlib==3.1.0 +attrs==21.2.0 +pycparser==2.20 +defusedxml==0.7.1 +xlrd==1.2.0 +mock==2.0.0 +filelock==3.0.12 +plotly==4.8.1 +sacremoses==0.0.45 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 +Shapely==1.7.0 +yellowbrick==1.1 +jmespath==0.10.0 CairoSVG==2.5.2 -jmespath==0.10.0 -pydot==1.4.1 +tqdm==4.46.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 +python-jsonrpc-server==0.0.1 +transformers==2.5.1 +graphviz==0.14 +func-timeout==4.3.5 +tinycss2==1.0.2 +pytorch-pretrained-bert==0.6.2 +click==7.1.2 +toolz==0.9.0 +sympy==1.6.2 +Augmentor==0.2.8 +pygame==2.0.1 +regex==2021.4.4 +packaging==20.9 +word2vec==0.10.6 +configparser==4.0.2 +dask==0.20.0 +baytune==0.3.10 +tf-slim==1.1.0 +networkx==2.2 metakernel==0.27.5 +rouge==1.0.0 +mpmath==1.2.1 +minepy==1.2.4 +openpyxl==2.6.4 +importlib-resources==3.2.1 +torchtext==0.6.0 +appdirs==1.4.4 +nltk==3.5 +unification==0.2.2 multipledispatch==0.6.0 -plotly==4.8.1 -async-generator==1.10 +tokenizers==0.5.2 +minio==5.0.10 +cloudpickle==0.6.1 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 +pyrsistent==0.17.3 +kanren==0.2.3 +opencv-contrib-python==4.4.0.42 +pyOpenSSL==20.0.1 +imageio-ffmpeg==0.4.4 +pyenchant==3.1.1 +tensorboardX==2.0 +tensorflow-estimator==1.13.0 +imgaug==0.2.6 +cryptography==3.2.1 +Cython==0.29.20 +s3transfer==0.3.3 +zipp==1.2.0 +sentencepiece==0.1.91 +torchvision==0.5.0+cpu jupyterlab-server==0.2.0 -minio==5.0.10 -graphviz==0.14 +ipdb==0.13.2 +distlib==0.3.1 +numpyencoder==0.3.0 +imageio==2.8.0 diff --git a/test.ipynb b/test.ipynb index 9e2543a..375fe92 100644 --- a/test.ipynb +++ b/test.ipynb @@ -2,10 +2,82 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [] + "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['诗词形式'] # 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": {