Beispiel #1
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 iapp 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
Beispiel #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 iapp 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)



Beispiel #3
0
    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 iapp import App

_app = App()
_app.app = app


def predict(**kwargs):
    return n


_app.add_route('/model', predict)

_app.run()
Beispiel #4
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 iapp 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)
Beispiel #5
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)
Beispiel #6
0
    global d
    d = d - 1
    print(d, 1 / d)

    logging.warning(time.ctime())

    global dt
    dt = time.ctime()
    return dt


scheduler = Scheduler()
scheduler.add_job(task, seconds=10)
scheduler.start()

dt = task()
# Api
update = lambda **kwargs: dt
pred1 = lambda **kwargs: kwargs['x'] + kwargs['y']
pred2 = lambda x=1, y=1: x - y
pred3 = lambda text='小米是家不错的公司': jieba.lcut(text)

app = App()
app.add_route("/", update, version="1")
app.add_route("/", update, methods="POST")

app.add_route("/f1", pred1, version="1")
app.add_route("/f2", pred2, version="2")
if __name__ == '__main__':
    app.run(debug=True, port=8899)
Beispiel #7
0
# @File         : main
# @Time         : 2019-08-30 17:31
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  :

import os

os.environ[
    '--models'] = '/Users/yuanjie/Desktop/Projects/Python/tql-App/examples/fds/models'
os.environ[
    '--flag'] = '/Users/yuanjie/Desktop/Projects/Python/tql-App/examples/fds'
flag = __import__('hotflag').flag

from iapp import App
from examples.fds.update import model2transformer

app = App()


def predict(**kwargs):
    model_name = kwargs["model_name"]  # sklearn_lr_demo.model
    (predict, feature_transform) = model2transformer.get(model_name)
    X = feature_transform(**kwargs)  # 二维数组
    return predict(X)


app.add_route('/deploy', predict, methods="POST", flag=flag)
app.run()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : tql-App.
# @File         : ann_search
# @Time         : 2020/11/5 4:04 下午
# @Author       : yuanjie
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  : 

import requests
from functools import lru_cache
from iapp import App

app_ = App()
app = app_.app


@lru_cache(256)
def get_bert_vector(text):
    return requests.get(f"http://tql.algo.browser.miui.srv/bert/simbert?texts=['{text}']").json()['vectors']


def xindao_search(**kwargs):
    text = kwargs.get('text', '')
    topk = kwargs.get('topk', 5)
    return_ids = kwargs.get('return_ids', 0)

    query_embedding = get_bert_vector(text)
    body = {
        "query": {
Beispiel #9
0
import numpy as np
from iapp import App
from paddleocr import PaddleOCR

ocr = PaddleOCR(use_angle_cls=True, lang="ch")


def get_ocr_result(**kwargs):
    results = []
    image_urls = kwargs.get('image_urls', [])

    for image_url in image_urls:
        os.system(f"wget {image_url} -O image")
        result = ocr.ocr('image', cls=True)  # todo

        results.append(result)
    return eval(str(results))


app_ = App()
app_.add_route('/ocr', get_ocr_result, method="POST")

app = app_.app
if __name__ == '__main__':

    # app.run(port=9955, debug=False, reload=False)
    app_.run(f"{app_.app_file_name(__file__)}",
             port=9955,
             debug=False,
             reload=False)
Beispiel #10
0
# @Email        : [email protected]
# @Software     : PyCharm
# @Description  : 


from iapp import App
import time



##############update
a = 666

def update(**kwargs):
    time.sleep(10)

    global a
    a = kwargs
    return a
##############

app = App(1, workers=2)
# update
app.add_route("/update", update, time=time.ctime())

f1 = lambda **kwargs: a
app.add_route("/f1", f1, time=time.ctime())

f2 = lambda **kwargs: 666
app.add_route("/f2", f2, time=time.ctime())
app.run()
Beispiel #11
0
# @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 iapp.scheduler import SanicScheduler, task

import jieba
from iapp 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())