如何在可公开访问的服务器上运行 Spacy 模型?

问题描述 投票:0回答:1

我正在用 python 运行一个语言分析程序。我的本地主机上已经运行了以下代码:

from flask import Flask, request, jsonify, render_template
import en_core_web_sm
from rules import *

nlp = en_core_web_sm.load()

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/api/rule1', methods=['POST'])
def process_text_r1():
    try:
        text = request.json.get('text', '')

        if not text:
            return jsonify({'error': 'Text not provided'}), 400

        result = rule1(nlp,text)
        return jsonify({'result': result})

    except Exception as e:
        return jsonify({'error': 'Internal server error', 'message': str(e)}), 500

我希望能够从可公开访问的服务器上运行它。

我尝试将应用程序上传到 Vercel,但随后 Vercel 警告说它超出了应用程序的限制。限制是 50MB,鉴于我的代码只有 8KB,所以我不明白它是怎么变得这么大的。

我试过在托管服务提供商 (namecheap) 上创建一个应用程序,但这个过程似乎太复杂了。

python flask nlp localhost spacy
1个回答
0
投票

你的应用程序可能超过了 50mb 的限制,因为

en_core_web_sm
模型本身和其他库(例如,请求,jsonify)你的应用程序实际上超过 50mb,尽管你的源代码是 8kb。

像 namecheap 这样的托管服务提供商并不是最好的选择,因为他们的平台主要是为网页服务而设计的,所以他们只支持一些常见的部署过程(例如 Wordpress、PHP、node.js)。

您可以尝试一些替代方案:

© www.soinside.com 2019 - 2024. All rights reserved.