我的代码-flask

  

import pickle
import flask
import pandas as pd
import json
from flask import Flask
from flask import request, render_template
from sklearn.externals import joblib

app = Flask(__name__)
app.url_map.strict_slashes = False

model= joblib.load('E:/ModelOnGoing/Project-Etcher/ModelLive/model_RF_test.pkl','r')
@app.route("/predict",methods=["POST"])
def predict():
features_array = request.get_json()
data = pd.read_json(json.dumps(features_array),orient='records')
prediction=model.predict(data).tolist()
response={}
response['predictions']=prediction

return flask.jsonify(response)



if __name__ == '__main__':
try:
port = int(sys.argv[1]) # This is for a command-line input
except:
port = 12345 # If you don't provide any port the port will be set to 12345
app.run(port=port,debug=True)

 

 

 

 

import json
import csv
import pandas as pd
import numpy as np
import requests
from os import listdir
from os.path import isfile, join
import time

url="http://127.0.0.1:12345/predict"
mypath = r"E:/Data/Project-Etcher/PredictData"
for j in range(200000000):

onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
for file in onlyfiles:
df=pd.read_csv(mypath + "\\" + file)
#df1=df.drop("Target",axis=1)
df=df.iloc[:,1:]
#df2=df1.head(1000)
df3=df.to_json(orient='records')
headers={'content-type':'application/json','Accept-Charset':'UTF-8'}
r=requests.post(url,data=df3, headers=headers)
print(r.text)
predictions=r.text
predictions=pd.read_json(predictions)
df['predictions_value']=predictions
output=("E:\Data\Project-Etcher\PredictRes\PredictRes_RF")
df.to_csv(output + "\\" + "Results" + file)
time.sleep(60)
print("No Files in the folder, will check again")
j+1
#df2.to_csv('D:/Users/sgg91139/Desktop/api/result.csv')
#df1.to_csv('D:/Users/sgg91139/Desktop/try/results.csv')
#print (df)

 

 

 


# coding: utf-8

# In[19]:

 

import pandas as pd
import numpy as np
import scipy as sp
import time
import shutil
from os import listdir
from os.path import isfile, join,splitext


# In[ ]:


Res_path = r"E:\Data\Project-Etcher\PredictRes\PredictRes_RF"
Index_path = r"E:\Data\Project-Etcher\PredictIndex"
FinalRes_path=r"E:\Data\Project-Etcher\JoiningRes\JoiningRes_RF"
for j in range(200000):

Index_files = [f for f in listdir(Index_path) if isfile(join(Index_path, f))]
for file in Index_files:
data1=pd.read_csv(Index_path + "\\" + file)
data1=data1.iloc[:,1:]
file_cut= file[-15:-4]
print("get data, wait 30s for the model to do prediction.")
time.sleep(30)
data2= pd.read_csv(Res_path + "\\" + "ResultsAEM2_pivotdata_" + file_cut + ".csv")
data2= data2.iloc[:,1:]
data=pd.concat([data1,data2],axis=1)
data=data.drop(columns=["wafer1","chamber1","eqpid1","ETCM_PHA4","ETCM_PHB4","ETCM_PHC4","HELK_MEAN","LOWERCHM_PRESS","PBK4","RR13_MAX.","RR13_MEAN","RR23_MAX.","RR23_MEAN","THR3_MAX.","THR3_MAX._DIFF","THR3_MEAN","THR3_MEAN_DIFF","THR3_MEAN_SLOPE","SUM_ETCM"])
data.to_csv(FinalRes_path + "\\" + "FinalResultsAEM2_" + file_cut + ".csv")
shutil.move(Res_path + "\\" + "ResultsAEM2_pivotdata_" + file_cut + ".csv",r'E:\Data\Project-Etcher\PredictRes_Processed')
shutil.move(Index_path + "\\" + file,r'E:\Data\Project-Etcher\PredictIndex_Processed')
if any(data.predictions_value) == 1:
print("predict to have bad wafer,please check triggering result folder.")
shutil.move(FinalRes_path + "\\" + "FinalResultsAEM2_" + file_cut + ".csv",r'E:\Data\Project-Etcher\FinalRes')
else:
print("predict that all are good wafers.")
print("no result file need to join, will check again after 1 mins." )
time.sleep(60)
j+1

 

posted on 2018-12-19 10:32  Aimee0207  阅读(180)  评论(0编辑  收藏  举报

导航