Spaces:
Runtime error
Runtime error
from flask import Flask, request, jsonify, make_response, render_template | |
from do_predict import predict_single | |
app = Flask(__name__) | |
app.config["JSON_AS_ASCII"] = False | |
def index(): | |
return render_template("index.html") | |
def before(): | |
# handle preflight | |
if request.method == "OPTIONS": | |
resp = make_response() | |
resp.headers["Access-Control-Allow-Origin"] = "*" | |
resp.headers["Access-Control-Allow-Methods"] = "GET, POST" | |
resp.headers["Access-Control-Allow-Headers"] = "Content-Type" | |
return resp | |
def api_predict_single(): | |
text = request.json["text"] | |
result = predict_single(text) | |
resp = jsonify(result) | |
resp.headers["Access-Control-Allow-Origin"] = "*" | |
return resp | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0", port=22222) | |