Spaces:
Sleeping
Sleeping
jsaplication
commited on
Commit
•
602b069
1
Parent(s):
9238cce
Update app.py
Browse files
app.py
CHANGED
@@ -77,25 +77,35 @@ app = Flask(__name__)
|
|
77 |
@app.route('/reconstruir', methods=['POST'])
|
78 |
def reconstruir_imagem():
|
79 |
try:
|
|
|
|
|
80 |
version = request.form.get('version',"v1.4")
|
81 |
scale = int(request.form.get('scale',2))
|
82 |
img_file = request.files['imagem']
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
else:
|
95 |
-
return jsonify({'error': 'Falha na reconstrução da imagem'})
|
96 |
|
|
|
|
|
|
|
97 |
except Exception as e:
|
98 |
-
return jsonify({'error': str(e)})
|
99 |
|
100 |
if __name__ == '__main__':
|
101 |
app.run(host='0.0.0.0', port=80)
|
|
|
77 |
@app.route('/reconstruir', methods=['POST'])
|
78 |
def reconstruir_imagem():
|
79 |
try:
|
80 |
+
|
81 |
+
token = request.form.get('token')
|
82 |
version = request.form.get('version',"v1.4")
|
83 |
scale = int(request.form.get('scale',2))
|
84 |
img_file = request.files['imagem']
|
85 |
|
86 |
+
if token == "api_key_abcd":
|
87 |
+
|
88 |
+
temp_filename = 'temp.jpg'
|
89 |
+
img_file.save(temp_filename)
|
90 |
|
91 |
+
output, save_path = inference(temp_filename, version, scale)
|
92 |
|
93 |
+
if output is not None:
|
94 |
+
# return send_file(save_path, mimetype='image/jpeg')
|
95 |
+
with open(save_path, 'rb') as image_file:
|
96 |
+
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
|
97 |
+
return jsonify({'status': 'success', 'message':'Imagem restaurada com sucesso', 'image_base64': encoded_image})
|
98 |
+
else:
|
99 |
+
return jsonify({'status': 'error', 'message':'Falha na reconstrução da imagem'})
|
100 |
+
|
101 |
+
|
102 |
else:
|
|
|
103 |
|
104 |
+
return jsonify({'status': 'error', 'message': 'Token invalido'})
|
105 |
+
|
106 |
+
|
107 |
except Exception as e:
|
108 |
+
return jsonify({'status': 'error', 'message': str(e)})
|
109 |
|
110 |
if __name__ == '__main__':
|
111 |
app.run(host='0.0.0.0', port=80)
|