我的代码-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
我的代码-flask的更多相关文章
- flask 第二章 endpoint重名 Flask路由 初始化配置 Falsk Config 蓝图+目录结构
今日内容 1.路由的分发,以下两种方式效果一样,但是都能指向同一个函数 from flask import Flask app=Flask(__name__) #第一种方式 @app.route('/ ...
- flask请求上下文
先看一个例子: #!/usr/bin/env python # -*- coding:utf-8 -*- import threading # local_values = threading.loc ...
- Flask系列之源码分析(一)
目录: 涉及知识点 Flask框架原理 简单示例 路由系统原理源码分析 请求流程简单源码分析 响应流程简单源码分析 session简单源码分析 涉及知识点 1.装饰器 闭包思想 def wapper( ...
- flask中请求勾子
请求勾子 在客户端和服务器交互的过程中,有些准备工作或扫尾工作需要处理,比如: *在请求开始时,建立数据库连接; *在请求开始时,根据需求进行权限校验; *在请求结束时,指定数据的交互格式; 为了让每 ...
- 22、Flask实战第22天:Flask信号
Flask中的信号使用的是一个第三方插件blinker.通过pip list看一下是否安装,如果没有,则使用如下命令安装 pip install blinker 自定义信号 自定义信号分为3步: ①定 ...
- Flask纪要
flask学习过程 1框架基础 2redis高性能key-value数据库 3视图具有装饰器的路由函数 4模板html文件 面向对象操作数据库orm 5蓝图 6单元测试 7GitHub 8项目 学习的 ...
- 面试简历书写、Flask框架介绍与快速使用、Flask演示登录页面、用户信息页面案例
今日内容概要 面试简历编写 Flask框架介绍与安装 内容详细 1.面试简历编写 # 千万不要几个小时把简历凑出来 几天到一周 # 有没有面试机会,取决于简历写得怎么样 简历写好是第一步 # 投简历的 ...
- 巨蟒python全栈开发flask2
内容回顾: 上节回顾: Flask .response 三剑客: render_template 模板 redirect 重定向 - URL地址 "" 字符串 HTTPRespon ...
- Python面试题集合带答案
目录 Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Python的 ...
随机推荐
- git切换用户踩坑
1)配置用户信息 git config --global user.name "username" git config --global user.email "**@ ...
- go ethereum源码分析 PartIV Transaction相关
核心数据结构: core.types.transaction.go type Transaction struct { data txdata // caches hash atomic.Value ...
- 常用正则表达式 c#
/// <summary> /// 是否手机号 /// </summary> /// <param name="str"></param& ...
- C_program assignment 2
/* Name: C program assignment 2 Copyright: Author: ShiroKa_X Date: 22/03/17 14:07 Description: */ #i ...
- Jmeter之正则表达式提取器应用
说到Jmeter正则表达式提取器的应用,就不得不说到关联.所谓关联,就是把应用中动态变化返回的数据获取到,把它保存为一个参数,提供给后面需要用到的地方进行使用. Jmeter中关联是通过“添加—后置处 ...
- Mybatis第一天
Mybatis第一天 框架课程 1. 课程计划 第一天: 1.Mybatis的介绍 2.Mybatis的入门 a) 使用jdbc操作数据库存在的问题 b) Mybatis ...
- win10 如何关掉自带的杀毒软件 window defender
问题描述: win10系统,自带的杀毒软件 window defender 会实时保护电脑对文件进行检测,将认为的病毒文件自动清除, 造成我想下载的MDK5的注册机一直下载不成功,即使从别处拷贝过来, ...
- CSS3简单画出3d图形
1.气球 2.泳圈 1.2两图实现代码分别如下: <html> <head> <meta charset="utf-8"> <meta h ...
- Linux----Github环境搭建
前面介绍了在Windows环境上安转GitHub环境,原本以为打包成jar,发布到Linux不需要再安转Git,但是因为我们使用了Config-Server配置中心,远程配置来启动,所以需要在Linu ...
- 使用Babel将单独的js文件 中的 ES6转码为ES5
如果你并没有接触过ES6,当你看到下面的代码时,肯定是有点懵逼的(这是什么鬼?心中一万头神兽奔腾而过),但是你没看错,这就是ES6.不管你看不看它,它都在这里. 1 2 3 4 5 6 7 8 9 ...