コード例 #1
0
    is_lite = kwargs.get('is_lite', 0)

    vecs = text2vec(text)
    if is_lite:
        vecs = vecs[:, range(0, 768, 4)]  # 64*3 = 192维度

    return normalize(vecs).tolist()


def get_batch_vec(**kwargs):
    texts = kwargs.get('texts', ['默认'])
    is_lite = kwargs.get('is_lite', 0)

    vecs = texts2vec(texts)

    if is_lite:
        vecs = vecs[:, range(0, 768, 4)]  # 64*3 = 192维度

    return normalize(vecs).tolist()


logger.info(f"初始化模型: {text2vec('语言模型')}")  # 不初始化会报线程错误

if __name__ == '__main__':
    app = App(verbose=os.environ.get('verbose'))

    app.add_route('/simbert', get_one_vec, result_key='vectors')
    app.add_route('/simbert', get_batch_vec, 'POST', result_key='vectors')

    app.run(access_log=False)
コード例 #2
0
app = Sanic(__name__)
model_map = {}
@app.route("/update", methods=['GET', 'POST'])
async def update(request):
    global n
    n = len(open("./new_tree.yml").read())
    return text('OK')

@app.route("/files", methods=['GET', 'POST'])
async def post_json(request):

    test_file = request.files.get('file')

    basepath = os.path.dirname(__file__)
    file_path = os.path.join(basepath, './', test_file.name)
    with open(file_path, 'wb') as f:
        f.write(test_file.body)

    return redirect('/update')

from appzoo import App

_app = App()
_app.app = app

def predict(**kwargs):
    return n

_app.add_route('/model', predict)

_app.run()
コード例 #3
0
@task(timedelta(hours=1), time(hour=1, minute=30))
async def foo_bar(_):
    """Runs the function every 1 hours after 1:30."""
    print("Foo", datetime.now())
    await asyncio.sleep(1)
    print("Bar")


@task(timedelta(minutes=2), timedelta(seconds=10))
def baz(_):
    """Runs the function every 2 minutes after 10 seconds."""
    print("Baz", datetime.now())


@task(start=timedelta(seconds=10))
def another(_):
    """Run the function after 10 seconds once."""
    print("another", datetime.now())


from appzoo import App

app_ = App()
app_.app = app

app_.add_route('/', lambda **kwargs: d)  #  values.get_value()

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True, workers=4)
コード例 #4
0
    dt_feat = d.pop('createTime') + d.pop('publishTime')
    r = list(d.values()) + dt_feat
    return [r]


# Api
# @logger.catch
def predict_strict(**ac):
    X = get_feats(ac)
    text = ac.get("title", "请输入一个文本")

    return merge_score(X, text, 'strict')


def predict_nostrict(**ac):
    X = get_feats(ac)
    text = ac.get("title", "请输入一个文本")

    return merge_score(X, text, 'nostrict')


if __name__ == '__main__':
    from appzoo import App

    app = App(verbose=os.environ.get('verbose'))
    app.add_route('/nh/strict', predict_strict, method="POST")
    app.add_route('/nh/nostrict', predict_nostrict, method="POST")

    app.run(port=8000, access_log=False)
コード例 #5
0
                            "values": query_embedding,
                            "metric_type": "IP",
                            "params": {
                                "nprobe": 1
                            }
                        }
                    }
                }]
            }
        },
        "fields": []
    }

    r = requests.get(xindao_search_url, json=body).json()
    if return_ids:
        return [i['id'] for i in r['data']['result'][0]]
    else:
        return r


app_ = App()
app = app_.app

app_.add_route('/xindao_search', xindao_search)

if __name__ == '__main__':
    app_.run(f"{app_.app_file_name(__file__)}",
             port=9955,
             debug=True,
             reload=True)
コード例 #6
0
ファイル: appzoo_demo.py プロジェクト: Jie-Yuan/AppZoo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : AppZoo.
# @File         : appzoo_demo
# @Time         : 2021/2/8 5:43 下午
# @Author       : yuanjie
# @WeChat       : 313303303
# @Software     : PyCharm
# @Description  :

from appzoo import App

app = App()


def func(**kwargs):
    print(kwargs)
    return kwargs


app.add_route('/', func, "GET")
app.add_route('/', func, "POST")

app.run()
コード例 #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : tql-App.
# @File         : fastApiDemo
# @Time         : 2020/10/22 4:22 下午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  :

from appzoo import App

func = lambda **kwargs: kwargs

app_ = App()

app_.add_route("/demo", func, version=1)
app_.add_route("/demo_", func)

app = app_.app

if __name__ == '__main__':
    # app.run(port=1234)
    app_.run(app_.app_file_name(__file__), port=4321, debug=True, reload=True)
コード例 #8
0
        batch_segment_ids.append(segment_ids)
    batch_token_ids = sequence_padding(batch_token_ids)
    batch_segment_ids = sequence_padding(batch_segment_ids)
    return batch_token_ids, batch_segment_ids


# Api
def predict_one(**kwargs):
    text = kwargs.get("text", "请输入一个文本")
    scores = model.predict(texts2seq(text))[:, 1].tolist()
    return list(zip([text], scores))


def predict_batch(**kwargs):
    texts = kwargs.get("texts", ["请输入一批文本"])
    scores = model.predict(texts2seq(texts))[:, 1].tolist()
    return list(zip(texts, scores))


logger.info(predict_one())

if __name__ == '__main__':
    from appzoo import App

    app = App()
    app.add_route('/nh_bert/predict_one', predict_one, method="GET")
    app.add_route('/nh_bert/predict_one', predict_one, method="POST")
    app.add_route('/nh_bert/predict_batch', predict_batch, method="POST")

    app.run(port=9966, access_log=False)
コード例 #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : tql-Python.
# @File         : demo
# @Time         : 2019-08-15 10:20
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  :

from appzoo import App
import time

app = App()

f1 = lambda **kwargs: 666


def f1(**kwargs):
    with open('./log.txt', 'a') as f:
        f.write("666\n")


with open('./log.txt') as f:
    n = len(list(f))


def f2(**kwargs):
    global n
    return n + 1111111111
コード例 #10
0
ファイル: mongo_item.py プロジェクト: Jie-Yuan/AppZoo
    def default(self, o):
        if isinstance(o, ObjectId):
            return str(o)
        return json.JSONEncoder.default(self, o)


def insert(**kwargs):
    kwargs.pop('_id', None)

    logger.info(kwargs)

    c.insert(kwargs)
    return 'ok'


def query(**kwargs):
    logger.info(kwargs)
    rst = c.find_one(kwargs)

    return JSONEncoder().encode(rst)


if __name__ == '__main__':
    from appzoo import App

    app = App()
    app.add_route('/mongocache/item/insert', insert, method="POST")
    app.add_route('/mongocache/item/query', query, method="GET")

    app.run(port=8000, access_log=False)
コード例 #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : AppZoo.
# @File         : lite_app
# @Time         : 2020/12/3 2:21 下午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  : 方便联调起的空服务

from meutils.pipe import *


def predict(**kwargs):
    print(kwargs)
    return kwargs


if __name__ == '__main__':
    from appzoo import App

    app = App()
    app.add_route('/', predict, method="POST")

    app.run(port=8000, access_log=True)
コード例 #12
0
# @Project      : AppZoo.
# @File         : zk_hot_update
# @Time         : 2020/12/3 5:33 下午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  : 

from meutils.zk_utils import *
from meutils.pipe import *

@zk.DataWatch('/mipush/nh_model')
def watcher(data, stat):  # (data, stat, event)
    ZKConfig.info = yaml.safe_load(data)
    print(ZKConfig.info)

logger.info(ZKConfig.info) # 只打印一次


def func(**kwargs):
    return ZKConfig.info


if __name__ == '__main__':
    from appzoo import App

    app = App()
    app.add_route('/', func, method="GET")

    app.run(port=8000, access_log=False)
コード例 #13
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : tql-App.
# @File         : nlp_app
# @Time         : 2020/11/4 10:24 上午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  : 


from appzoo import App
import jieba.analyse  as ja

app = App()
app.add_route('/get', lambda **kwargs: ja.tfidf(kwargs.get('text', '')), method="GET", result_key="keywords")
app.run(port=9955, debug=False, reload=False)
コード例 #14
0
ファイル: scheduler.py プロジェクト: Jie-Yuan/AppZoo
# @Project      : tql-App.
# @File         : scheduler
# @Time         : 2019-09-02 13:17
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  :
import asyncio

from datetime import datetime, time, timedelta
from appzoo.scheduler import SanicScheduler, task

import jieba
from appzoo import App

app = App(debug=True)
scheduler = SanicScheduler(app.app, False)  # CST 非 UTC

c1 = {}
c2 = {}
c3 = {}


@task(timedelta(seconds=10))  # 实现初始化
def hello1(xx):
    c1['n'] = c1.get('n', 0) + 1

    print('c1:', c1)
    print("Hello, {0}".format(xx), datetime.now())

コード例 #15
0
        w, h = Image.open('image').size
        image_result = ocr.ocr('image', cls=True)  # todo
        results.append(text_match_flag(image_result, w, h))

        os.system(f"rm water_mark_image")

    return results


def get_water_mark_from_docid(**kwargs):
    docid = kwargs.get('docid', '0003899b202871b7fd3dab15f2f9549a')
    url = f'{ac_url}/{docid}'
    ac = request(url)['item']
    return get_water_mark(image_urls=list(ac['imageFeatures']))


app_ = App()
app_.add_route('/ocr', get_ocr_result, method="POST")
app_.add_route('/ocr/water_mark', get_water_mark, method="POST")
app_.add_route('/ocr/water_mark', get_water_mark_from_docid, method="GET")

app = app_.app
if __name__ == '__main__':
    # app.run(port=9955, debug=False, reload=False)
    app_.run(f"{app_.app_file_name(__file__)}",
             port=9955,
             access_log=False,
             debug=False,
             reload=False)
コード例 #16
0
ファイル: nlp_app.py プロジェクト: Jie-Yuan/AppZoo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : tql-App.
# @File         : nlp_app
# @Time         : 2020/11/4 10:24 上午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  :

from appzoo import App
import jieba.analyse as ja

app = App()
app.add_route('/get/{text}',
              lambda **kwargs: ja.tfidf(kwargs.get('text', '')),
              method="GET",
              text="")
app.run(port=9955, debug=False, reload=False)
コード例 #17
0
ファイル: demo.py プロジェクト: streamlit-badge-bot/AppZoo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : AppZoo.
# @File         : demo
# @Time         : 2020/11/5 8:19 下午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  :

from appzoo import App

app = App()

if __name__ == '__main__':
    app.add_route('/',
                  lambda **kwargs: "Hello World",
                  method="GET",
                  result_key="result")
    app.run(port=9955)
コード例 #18
0
ファイル: demo3.py プロジェクト: streamlit-badge-bot/AppZoo
    return model_map


f1 = lambda **kwargs: model_map
f2 = lambda **kwargs: d


def api(**kwargs):
    print(kwargs)
    print(kwargs.get('method')[0])
    a = eval(kwargs.get('method')[0])(**kwargs)
    return a


##############

app = App()

# app.app.add_task(task())

# update
app.add_route("/update", update, time=time.ctime())

app.add_route("/f1", f1, time=time.ctime())

app.add_route("/f2", f2, time=time.ctime())

app.add_route("/api", api, time=time.ctime())

app.run(workers=1, debug=True, access_log=True, port=9955)
コード例 #19
0
        S.append(s)
    X = sequence_padding(X)
    S = sequence_padding(S)

    ################################################################
    # topK
    Z = encoder.predict([X, S])
    Z /= (Z**2).sum(axis=1, keepdims=True)**0.5
    argsort = np.dot(Z[1:], -Z[0]).argsort()
    return [r[i + 1] for i in argsort[:k]]


logger.info(f"初始化:{gen_synonyms('支付宝', 1, 1)}")


def gen_synonyms_(**kwargs):
    text = kwargs.get('text', '小米非常好')
    n = int(kwargs.get('n', 50))
    k = int(kwargs.get('k', 5))

    return gen_synonyms(text, n, k)


if __name__ == '__main__':
    from appzoo import App

    app = App()
    app.add_route('/gen_synonyms', gen_synonyms_, method="GET")

    app.run(port=8000, access_log=False)