<jupyter_start><jupyter_text>Hello World API using Flask<jupyter_code>import os
hello_world_script_file = os.path.join(os.path.pardir, 'src', 'models', 'hello_world_api.py')
%%writefile $hello_world_script_file

from flask import Flask, request

app = Flask(__name__)

@app.route('/api', methods=['POST'])
def say_hello():
    data = request.get_json(force=True)
    name = data['name']
    return "hello {0}".format(name)

if __name__ == '__main__':
    app.run(port=10001, debug=True)
import json, requests
url = 'http://127.0.0.1:10001/api'
data = json.dumps({'name': 'abhi'})
r = requests.post(url, data)
print(r.text)<jupyter_output>hello abhi<jupyter_text>Machine Learnings API using Flask  Building API<jupyter_code>import os
ml_api_script_file = os.path.join(os.path.pardir, 'src', 'models', 'machine_learning_api.py')
%%writefile $ml_api_script_file

from flask import Flask, request
import pandas as pd
import numpy as np
import json, requests, pickle

app = Flask(__name__)

# Load model and scaler files
model_path
model_file_path = os.path.join(os.path.pardir, 'models', 'model_logit.pkl')
scaler_file_path = os.path.join(os.path.pardir, 'models', 'scaler_logit.pkl')

model = pickle.load(open(model_file_path, 'rb'))
scaler = pickle.load(open(scaler_file_path, 'rb'))

# columns
column = 

@app.route('/api', methods=['POST'])
def say_hello():
    data = request.get_json(force=True)
    name = data['name']
    return "hello {0}".format(name)

if __name__ == '__main__':
    # host flask app at port 10001
    app.run(port=10001, debug=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.148171500630517, 'fraction_numerical': 0.017654476670870115, 'mean_word_length': 5.69620253164557, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '84475', 'license': 'FTL', 'n_tokens_mistral': 618, 'n_tokens_neox': 591, 'n_words': 126, 'path': 'notebooks/building_machine_learning_api.ipynb', 'repo_name': 'solanki111/data_science_project', 'size': '1586'}