Skip to content

Commit

Permalink
server code added with ui fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arshit09 committed Sep 20, 2019
1 parent 07f1731 commit 4594aef
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/server/models
/server/static
desktop.ini
3 changes: 0 additions & 3 deletions frontend/css/main.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@




/*//////////////////////////////////////////////////////////////////
[ FONT ]*/

Expand Down
38 changes: 38 additions & 0 deletions frontend/css/reset.min.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}

.left {
left: 0;
}

.right {
right: 0;
}

.megrim_font {
color: white;
margin-top: 5%;
font-size: 150%;
font-family: 'Julius Sans One';
}

.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}

.centered img {
width: 150px;
}

/* -------------------Default------------------ */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}table{border-collapse:collapse;border-spacing:0}@import url("https://fonts.googleapis.com/css?family=Work+Sans:400,700,900");

img {
Expand Down
68 changes: 58 additions & 10 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
document.getElementById('face_aging').style.display = 'none';
document.getElementById('image_to_map').style.display = 'none';
document.getElementById('object_removal').style.display = 'none';
document.getElementById('show_image').style.display = 'none';
document.getElementById(shown).style.display = 'block';
return false;
}
Expand All @@ -25,6 +26,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI Photo Editor</title>
<link rel="icon" href="image/o-letter.png" type="image/png" sizes="16x16">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="js/script.js"></script>
</head>

<body onload="return show('index');">
Expand Down Expand Up @@ -79,7 +83,8 @@
<div id="face_aging">
<nav class="black">
<div class="nav-wrapper">
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;" src="image/o-letter.png">to
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;"
src="image/o-letter.png">to
Editor</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#" onclick="return show('index');">Home</a></li>
Expand All @@ -93,7 +98,7 @@
<div class="row center" style="margin-top:4%; margin-right:3.77%;">
<div class="button" style="margin-inline-start: 4%">
<span class="button__mask"></span>
<span class="button__text">Upload<span>
<span class="button__text" onclick="sendFile('face_aging')">Upload<span>
<span class="button__text button__text--bis">Upload</span></div>
</div>
</div>
Expand All @@ -103,7 +108,8 @@
<div id="image_to_map">
<nav class="black">
<div class="nav-wrapper">
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;" src="image/o-letter.png">to
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;"
src="image/o-letter.png">to
Editor</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#" onclick="return show('index');">Home</a></li>
Expand All @@ -117,7 +123,7 @@
<div class="row center" style="margin-top:4%; margin-right:3.77%;">
<div class="button" style="margin-inline-start: 4%">
<span class="button__mask"></span>
<span class="button__text">Upload<span>
<span class="button__text" onclick="sendFile('image_to_map')">Upload<span>
<span class="button__text button__text--bis">Upload</span></div>
</div>
</div>
Expand All @@ -127,7 +133,8 @@
<div id="fogg_removal">
<nav class="black">
<div class="nav-wrapper">
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;" src="image/o-letter.png">to
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;"
src="image/o-letter.png">to
Editor</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#" onclick="return show('index');">Home</a></li>
Expand All @@ -141,7 +148,7 @@
<div class="row center" style="margin-top:4%; margin-right:3.77%;">
<div class="button" style="margin-inline-start: 4%">
<span class="button__mask"></span>
<span class="button__text">Upload<span>
<span class="button__text" onclick="sendFile('fogg_removal')">Upload<span>
<span class="button__text button__text--bis">Upload</span></div>
</div>
</div>
Expand All @@ -150,7 +157,8 @@
<div id="object_removal">
<nav class="black">
<div class="nav-wrapper">
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;" src="image/o-letter.png">to
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;"
src="image/o-letter.png">to
Editor</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#" onclick="return show('index');">Home</a></li>
Expand All @@ -164,7 +172,7 @@
<div class="row center" style="margin-top:4%; margin-right:3.77%;">
<div class="button" style="margin-inline-start: 4%">
<span class="button__mask"></span>
<span class="button__text">Upload<span>
<span class="button__text" onclick="sendFile('object_removal')">Upload<span>
<span class="button__text button__text--bis">Upload</span></div>
</div>
</div>
Expand All @@ -174,7 +182,8 @@
<div id="blur_to_hd">
<nav class="black">
<div class="nav-wrapper">
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;" src="image/o-letter.png">to
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;"
src="image/o-letter.png">to
Editor</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#" onclick="return show('index');">Home</a></li>
Expand All @@ -188,13 +197,52 @@
<div class="row center" style="margin-top:4%; margin-right:3.77%;">
<div class="button" style="margin-inline-start: 4%">
<span class="button__mask"></span>
<span class="button__text">Upload<span>
<span class="button__text" onclick="sendFile('blur_to_hd');return show('show_image');">Upload<span>
<span class="button__text button__text--bis">Upload</span></div>
</div>
</div>
</div>
</div>

<div id="show_image">
<nav class="black">
<div class="nav-wrapper">
<a href="#" class="brand-logo" onclick="return show('index');">AI Ph<img style="height:17px ;width:17px;"
src="image/o-letter.png">to
Editor</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#" onclick="return show('index');">Home</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</nav>

<div class="split left megrim_font">
<div class="centered">
<img id="input_image">
<div style="padding-top:50%;">Original Image</div>
</div>
</div>

<div class="split right megrim_font">
<div class="centered">
<img id="output_image">
<div style="padding-top:50%;">Generated Image</div>
</div>
</div>

<!-- <div id="output" style="display: none;">
<img id="input_image">
<img id="output_image">
</div> -->
</div>

<form style="display: none;" enctype="multipart/form-data" id="form">
<input type="file" name="image" id="input_handle">
<input type="text" id="type" name="type">
</form>

</body>

</html>
33 changes: 33 additions & 0 deletions frontend/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
server_url = "http://127.0.0.1:5000/process_image";

function sendFile(type){
$('#input_handle').click();
$('#type').val(type);
console.log(type);
}

$('document').ready(function(){
$('#input_handle').change(function(){
var data = new FormData($('#form')[0]);
$.ajax({
url: server_url,
data: data,
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success: function (data) {
$('#output').show();

var reader = new FileReader();
reader.onload = function (e) {
$('#input_image').attr('src', e.target.result);
}
reader.readAsDataURL($('#input_handle')[0].files[0]);

$('#output_image').attr("src", 'http://127.0.0.1:5000/static/uploads/' + data);
}
});
});
});
68 changes: 68 additions & 0 deletions server/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from flask import Flask, request, send_file
import tensorflow as tf
from keras.models import load_model
from keras.preprocessing.image import load_img, img_to_array, save_img
from flask_cors import CORS
import os
import random
import numpy as np


global graph
graph = tf.get_default_graph()

image_to_map = load_model('models/image_to_map.h5')

app = Flask(__name__)
CORS(app)
app.config['UPLOAD_FOLDER'] = 'static/uploads'
app.config['OUTPUT_FOLDER'] = 'static/outputs'

def predict(filename, process_type):
input_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
output_path = os.path.join(app.config['OUTPUT_FOLDER'], filename)

if process_type == 'object_removal':
pass
if process_type == 'fogg_removal':
pass
if process_type == 'image_to_map':
# size=(256,256)
# sat_img = load_img(input_path, target_size=size)
# sat_img = img_to_array(sat_img)
# # split into satellite and map
# sat_img = (sat_img - 127.5) / 127.5

# input_image=[]
# input_image.append(sat_img)
# input_image=np.array(input_image)
# gen_image=image_to_map.predict(input_image)
# gen_image=(gen_image+1)/2.0
# save_img(output_path, gen_image)
pass
if process_type == 'blur_to_hd':
pass
if process_type == 'face_aging':
pass


@app.route("/")
def index():
return "helllo"

chars = "abcdefghijklmnopqrstuvwxyz"

@app.route("/process_image", methods = ['POST'])
def process_image():
if 'image' in request.files:
file = request.files['image']
filename = ''.join(random.choice(chars) for x in range(10)) + '.' + file.filename.split('.')[-1]
path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
print(path)
file.save(path)
predict(filename, request.form['type'])
return filename
return "Hello"

if __name__ == '__main__':
app.run(debug = True)

0 comments on commit 4594aef

Please sign in to comment.