---
# System prepended metadata

title: Flask網頁

---

# Flask網頁

```
import os
import numpy as np
import pandas as pd 
import time
from sklearn.svm import SVC
from sklearn.externals import joblib
from sklearn.metrics import classification_report
import load_svm_model
from flask import Flask, request,render_template
from flask_uploads import UploadSet, configure_uploads, IMAGES,patch_request_class

app = Flask(__name__)
app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd()  

photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app)  

html = '''
	<!DOCTYPE html>
	<title>Upload File</title>
	<h1>image upload</h1>
	<form method=post enctype=multipart/form-data>
		 <input type=file name=photo>
		 <input type=submit value=上傳>
	</form>
	'''

@app.route('/', methods=['GET', 'POST'])
def upload_file():
	if request.method == 'POST' and 'photo' in request.files:
		filename = photos.save(request.files['photo'])
		file_url = photos.url(filename)
		return html + '<br><img src=' + file_url + '>' + '<br>' + "This image is " + pred
	return html


if __name__ == '__main__':

	df = pd.read_csv('./featuresOne.csv')
	#transform DataFrame to numpy.array
	DataSet=df.values 
	
	#make Format Feature:[[a1,b1,...,z1],.....[aN,bN,...,zN]]Label:[L1,L2,L3,...,LN]
	Feature = DataSet[:,2:]
	Label = DataSet[:,1:2]
	Label = Label.flatten()
	
	pred = load_svm_model.evaluate(Feature,Label)
	app.run(port=9000, debug=True)
```
第一部分是上傳圖片的時候先執行擷取特徵裡面的函式把CSV做出來再執行load_svm_model。
第二部分把load_svm_model.py import進去，執行裡面的函式。
