Last active
March 5, 2019 11:10
-
-
Save ardamavi/4effd9c0ed72ae1aa9d133a18da53c0f to your computer and use it in GitHub Desktop.
Keras - Django Web App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Arda Mavi - App</title> | |
</head> | |
<body> | |
<center> | |
<a style="text-decoration: none; font-size: 6em;" href="/"> | |
<span style="color:#fc4f3f;">Arda Mavi</span> <span style="color:#808080"></span> <span style="color:#3377CC;">App</span> | |
</a> | |
<br/><br/><br/> | |
<form method="post" action="/predict" enctype="multipart/form-data"> | |
{% csrf_token %} | |
<input type="file" name="image" accept="image/*" apture="camera"> | |
<br/><br/> | |
<button style="width: 100PX;" type="submit"><span>Predict</span></button> | |
</form> | |
<h4 style="color: #4a84cc;">{{ result|safe }}</h4> | |
<br/> | |
<h5 style="color: #515151;">Source: <a href="https://github.com/ardamavi" target="_blank" style="color: #515151; text-decoration: none;">github.com/ardamavi</a></h5> | |
<span style="color:#656565;">Copyright © 2017</span> | |
<br/> | |
<a style="text-decoration: none; font-size: 1.5em;" href="http://github.com/ardamavi.com" target="_blank"><span style="color:#808080">By</span> <span style="color:#fc4f3f;">Arda</span> <span style="color:#3377CC;">Mavi</span></a> | |
</center> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Arda Mavi | |
# Django views.py file: | |
from django.http import HttpResponse | |
from django.shortcuts import render | |
from keras.models import model_from_json | |
from scipy.misc import imresize | |
from PIL import Image | |
import numpy as np | |
def index(request): | |
return render(request, 'index.html', {'result': "Results"}) | |
def predict(request): | |
sonuc = 'Error!' | |
if request.method == 'POST' and request.FILES: | |
file_img = Image.open(request.FILES['image']) | |
image = np.array(file_img) | |
image = imresize(image, (200,200, 3)) | |
image = image.reshape(1, 200, 200, 3) | |
model_file = open('static/model.json', 'r') | |
model = model_file.read() | |
model_file.close() | |
model = model_from_json(model) | |
model.load_weights("static/weights.h5") | |
Y = model.predict(image) | |
result = np.argmax(Y, axis=1) | |
result = "<span style='color:#fc4f3f; font-size: 2em;'>{0}</span>".format(result) | |
else: | |
sonuc = "<span style='color:#fc4f3f;'>Your file couldn't found!</span>" | |
return render(request, 'index.html', {'result': result}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment