forked from masheilmir/DermaCareHacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (52 loc) · 2.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask import Flask, request, redirect, jsonify, render_template, url_for
import os
from werkzeug.utils import secure_filename
import sys
from google.oauth2 import service_account
from google.cloud import automl_v1beta1
from google.cloud.automl_v1beta1.proto import service_pb2
app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = "uploads"
@app.route("/")
def index():
return render_template('SkinCareSite.html')
@app.route("/SkinResult")
def SkinResult(request):
return render_template('SkinResult.html', request)
@app.route("/Blog")
def Blog():
return render_template("blog.html")
@app.route("/Contact")
def Contact():
return render_template("contactus.html")
@app.route("/Register")
def Register():
return render_template("register.html")
@app.route("/upload-image", methods=["GET", "POST"])
def upload_image():
if request.method == "POST":
if request.files:
image = request.files["image"].read()
#print(image)
content = bytes(image)
#predict.get_prediction(content, "ruhacks-277409", "ICN529872245611298816")
#with open("acnetest.jpg","rb") as image:
# f = image.read()
# b = bytearray(f)
#a = bytes(b)
#predict.get_prediction(, "ruhacks-277409", "ICN529872245611298816")
result = get_prediction(content, "ruhacks-277409", "ICN2611098223409889280")
print(result)
return render_template('SkinResult.html', request=result.payload[0].display_name)
#return redirect(url_for('SkinResult'))
return render_template('SkinCareSite.html')
def get_prediction(content, project_id, model_id):
credentials = service_account.Credentials. from_service_account_file('visionAPI.json')
prediction_client = automl_v1beta1.PredictionServiceClient(credentials=credentials)
name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id)
payload = {'image': {'image_bytes': content }}
params = {}
request = prediction_client.predict(name, payload, params)
return request
if __name__ == '__main__':
app.run(debug=False)