-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
368 additions
and
287 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea* | ||
*__pycache__ | ||
|
||
static/output | ||
|
File renamed without changes.
This file contains 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
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() |
Oops, something went wrong.