Last active
October 14, 2023 11:33
-
-
Save cloudsmithy/8ea17787212f473be20a4cfd6c7ebbf4 to your computer and use it in GitHub Desktop.
flask_ip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify | |
import requests | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
local_ip = requests.get('https://checkip.amazonaws.com').text.strip() | |
return jsonify({ | |
'ip': local_ip | |
}) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=10086, debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
import joblib | |
app = Flask(__name__) | |
# 加载预先训练好的模型 | |
model = joblib.load('path_to_your_model.pkl') | |
@app.route('/predict', methods=['POST']) | |
def predict(): | |
# 获取请求的数据 | |
data = request.get_json(force=True) | |
# 模型预测 | |
prediction = model.predict([data['features']]) | |
# 将预测结果转换为JSON格式并返回 | |
return jsonify(prediction=prediction[0]) | |
if __name__ == '__main__': | |
app.run(port=5000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment