我的代码-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的 ...
随机推荐
- 卸载和删除wozhuan.exe
在虚拟机里面,偶然发现CPU占用居高不下,打开任务管理器,发现有多个 wozhuan.exe 进程,这是个我从来没有见过的进程,顺手卸载后,没过多久,结果又出来了,可以判断,这肯定是虚拟机中奖了.中奖 ...
- mvc route .html 后缀 404
<system.webServer> <validation validateIntegratedModeConfiguration="false" /&g ...
- font awesome 页面小图标
font awesome 页面小图标 前段时间做页面,从网上查找资料,发现了一个好用的工具,就是font awesome奥森图标,使用了一下,发现非常方便,而且很灵活,纯css编写,可以和bootst ...
- Android Touch事件相关源码【Android SourceCode 2.3.6】
2018-05-31 17:23:46 Note: 这里的源码来自Android 2.3.6,这个版本的代码比较简单,适合理解Touch事件的传递原理.后续版本源码复杂了很多,但是原理都是类似的. 2 ...
- 与Recommender System相关的会议及期刊
会议 We refer specifically to ACM Recommender Systems (RecSys), established in 2007 and now the prem ...
- 生命周期--JSF
生命周期处理两种请求:初始请求和回发.当用户首次请求页面时,他或她正在首次请求该页面.当用户执行回发时,由于执行初始请求,他或她会提交以前加载到浏览器中的页面中包含的表单.当生命周期处理初始请求时,它 ...
- bash循环
bash脚本-循环02 bash脚本编程:循环 执行流程: 1.顺序执行 2.选择执行:if 3.循环执行:for,while,until 1.循环执行的条件 进入条件: for:列表元素非空 w ...
- 初识html与css
---恢复内容开始--- PS应用量尺寸w.h- 操作方式: 窗口,信息,右上角面板选项,标尺单位,像素切图- 操作方式: 切片工具, 文件 ,另存为web所有格式,jpeg,存储,切片:选中的切片, ...
- 1011. World Cup Betting (20)
生词(在文中的意思) tie 平局 lay a bet 打赌 putting their money where their mouths were 把他们的钱用在刀刃上 manner of 的方式 ...
- ;html5斜体字
font-style:italic; italic|oblique|normal 依次倾斜,越来越邪: