<jupyter_start><jupyter_text>deploy api<jupyter_code>df = df_raw.drop( 'quality', axis=1 )
df[(df['fixed acidity'] == 7.4) & (df['alcohol'] == 9.4) & (df['citric acid'] == 0.26)]
df_json = df.to_json( orient='records' )
#url = 'http://0.0.0.0:5000/predict'
url = 'https://wine-quality-model.herokuapp.com/predict'
data = df_json
header = {'Content-type': 'application/json'}

# Request
r = requests.post( url=url, data=data, headers=header )
print( r.status_code )
x = pd.DataFrame( r.json(), columns=r.json()[0].keys() )
x[(x['fixed acidity'] == 7.4) & (x['alcohol'] == 9.4) & (df['citric acid'] == 0.26)]<jupyter_output><empty_output><jupyter_text>Class In Production<jupyter_code>import pickle 

class WineQuality( object ):
    def __init__( self ):
        self.free_sulfur_scaler = pickle.load( open( '/Users/meigarom/repos/SejaUmDataScientist/deploy/free_sulfur_scaler.pkl', 'rb'))
        self.total_sulfur_scaler = pickle.load( open( '/Users/meigarom/repos/SejaUmDataScientist/deploy/total_sulfur_scaler.pkl', 'rb'))
        
    
    def data_preparation( self, df ):
        # rescaling free sulfur
        df['free sulfur dioxide'] = self.free_sulfur_scaler.transform( df['free sulfur dioxide'] )
        
        # rescaling total sulfur
        df['total sulfur dioxide'] = self.total_sulfur_scaler.transform( df['total sulfur dioxide'] )
        
        return df<jupyter_output><empty_output><jupyter_text>handler<jupyter_code>import pandas as pd
import pickle
from flask import Flask, request

from wine_quality import WineQuality

# load model
model = pickle.load(open('/Users/meigarom/repos/SejaUmDataScientist/deploy/model_wine_quality.pkl', 'rb'))

# instanciate flask
app = Flask( __name__ )

@app.route( '/predict', methods=['POST'] )  
def predict():
    test_json = request.get_json()

    # collect data
    if test_json:
        if isinstance( test_json, dict ): # unique value
            df_raw = pd.DataFrame( test_json, index=[0] )
        else:
            df_raw = pd.DataFrame( test_json, columns=test_json[0].keys() )

    # instanciate data preparation
    pipeline = WineQuality()

    # data preparation
    df1 = pipeline.data_preparation( df_raw )

    # prediction
    pred = model.predict( df1 )

    # response 
    df_raw['prediction'] = pred

    return df_raw.to_json( orient='records' )

if __name__ == '__main__':
    # star flask 
    app.run( host='0.0.0.0', port='5000' )
import pickle
import pandas as pd
from flask             import Flask, request, Response

from rossmann.Rossmann import Rossmann

# loading model
model = pickle.load(open('/Users/Igor/repos/Data-Science-Em-Producao/model/model_rossmann.pkl', 'rb'))

# initialize API
app = Flask(__name__)

@app.route('/rossmann/predict', methods = ['POST']) # endpoint, where the original data with the forecast will be sent
def rossmann_predict():
    test_json = request.get_json() # here pulls up the original csv files for both train and store
  
    if test_json: # there is data
          # json to dataframe conversion
        if isinstance(test_json, dict): # Unique example
            test_raw = pd.DataFrame(test_json, index =[0])
            
        else: # Multiple examples
            test_raw = pd.DataFrame(test_json, columns = test_json[0].keys())
            
        # instantiate Rossmann class # get the information from rossmann class
        pipeline = Rossmann()
        
        # data cleaning # model preparation 1
        df1 = pipeline.data_cleaning(test_raw)
        
        # feature engineering # model preparation 2 
        df2 = pipeline.feature_engineering(df1)
        
        # data preparation # model preparation 3
        df3 = pipeline.data_preparation(df2)
        
        # prediction
        df_response = pipeline.get_prediction(model, test_raw, df3)# test raw is the original data and df3 is the prepared data

       
        return df_response
    
    else:
        return Response('{}', status = 200, mimetype = 'application/json')
    
if __name__ == '__main__':
    app.run('127.0.0.1')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12224399804017638, 'fraction_numerical': 0.01396374326310632, 'mean_word_length': 3.1748466257668713, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '385453', 'license': 'MIT', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1301, 'n_words': 310, 'path': 'Data-Science-Em-Producao/Untitled1.ipynb', 'repo_name': 'IgorQueiroz32/Data_Science_Em_Producao', 'size': '4082'}