Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
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/{text}',
              lambda **kwargs: ja.tfidf(kwargs.get('text', '')),
              method="GET",
              text="")
app.run(port=9955, debug=False, reload=False)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
#!/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()
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
#!/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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 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)
Ejemplo n.º 12
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)