在windows上面跑多进程
pip install asgiref
pip install hypercorn
pip install Flask
pip install -U sentence-transformers
api.py
from flask import Flask, request
import json
from PIL import Image
from io import BytesIO
from sentence_transformers import SentenceTransformer
app = Flask(__name__)
# Load CLIP model
model = SentenceTransformer("./clip-ViT-B-32")
@app.route("/get")
def get():
return "hello world"
@app.route("/embeddings", methods=["POST"])
def check():
file_storage = request.files.get('file')
file_bytes = file_storage.read()
image = Image.open(BytesIO(file_bytes))
img_emb = model.encode(image)
return_dict = {'code': 200, 'message': 'success', 'data': img_emb.tolist()}
return json.dumps(return_dict, ensure_ascii=False)
# if __name__ == "__main__":
# app.run(debug=False, threaded=False, processes=2)
server.py
from api import app
from asgiref.wsgi import WsgiToAsgi # pip install asgiref
asgi_app = WsgiToAsgi(app)
运行
# server.py中的asgi_app
hypercorn -w 3 server:asgi_app