Skip to content

Commit

Permalink
refactor v1
Browse files Browse the repository at this point in the history
  • Loading branch information
andy1xx8 committed Sep 6, 2021
1 parent 2cfe69c commit 25350f4
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 287 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea*
*__pycache__

static/output

File renamed without changes.
79 changes: 26 additions & 53 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,41 @@
from flask import Flask, render_template, request, jsonify, send_from_directory, abort,send_file
from flask_cors import CORS
import time

from demo import *
from preprocessing_img import *
from flask import Flask, request
from flask_cors import CORS
from py_profiler.profiler_controller import profiler_blueprint

from enhance_service import *

app = Flask(__name__)
app.register_blueprint(profiler_blueprint)
CORS(app)
client_count=0 #to seperate

@app.route('/')
def index():
return "hello"
folder_out = "static/output/"
os.makedirs(folder_out, exist_ok=True)

enhance_service = EnhanceService(
'Deblurring/pretrained_models/model_deblurring.pth',
use_cpu=True
)

@app.route('/enhance',methods=['POST', 'GET'])
def enhance0():
if request.method == 'POST':
global client_count
urls=dict(request.get_json())['urls']
#
folder_in="static/clients/input/"+format(client_count,'04d')+"/"
folder_out="static/clients/output/"+format(client_count,'04d')+"/"
#
try:
os.makedirs(folder_in)
except:
pass
try:
os.makedirs(folder_out)
except:
pass
clear_folder(folder_in)
clear_folder(folder_out)
begin=time.time()
im_pre=Im_preprocess()
im_pre.close()
im_pre.from_urls_to_array(urls)
im_pre.write_img(folder_in)

process(folder_in,folder_out)
@app.route('/')
def index():
return "hello"

img_files=os.listdir(folder_out)
img_files.sort()

return_list=[]
for i in im_pre.correct_idx:
return_list.append({
'before':urls[im_pre.correct_idx[i]],
'after':'/get_image/'+format(client_count,'04d')+'/'+img_files[i]
})
client_count+=1
if client_count%499==0:
client_count=0
@app.route('/enhance', methods=['POST'])
def enhance():
urls = dict(request.get_json())['urls']
#
begin = time.time()
output_result = enhance_service.process(urls, folder_out)
print(f'Output: {output_result}')
return {
'time':time.time()-begin,
'result':return_list
'time': time.time() - begin,
'result': output_result
}
return {'message':'You need to use POST metod'}


@app.route('/get_image/<int:client_count>/<img_name>')
def get_image(client_count,img_name):
print('./static/clients/output'+format(client_count,'04d')+"/"+img_name)
return send_file('./static/clients/output/'+format(client_count,'04d')+"/"+img_name,attachment_filename=img_name,as_attachment=False)

if __name__ == '__main__':
app.run()
app.run()
175 changes: 0 additions & 175 deletions demo.py

This file was deleted.

Loading

0 comments on commit 25350f4

Please sign in to comment.