yeq6x commited on
Commit
ae27b39
·
1 Parent(s): bf46ec0

flask root('/')のgetを実装./process_refinedをendpointを分ける

Browse files
Files changed (1) hide show
  1. app.py +38 -35
app.py CHANGED
@@ -204,46 +204,49 @@ def handle_disconnect():
204
  redis_client.decr('connected_clients')
205
 
206
  # Flaskルート
207
- @app.route('/', methods=['GET', 'POST'])
 
 
 
 
 
 
208
  def process_refined():
209
- if request.method == 'POST':
210
- file = request.files['file']
211
- weight1 = float(request.form.get('weight1', 0.4))
212
- weight2 = float(request.form.get('weight2', 0.3))
213
-
214
- image = ensure_rgb(Image.open(file.stream))
215
- sotai_image, sketch_image = process_image_as_base64(image, "refine", weight1, weight2)
216
-
217
- return jsonify({
218
- 'sotai_image': sotai_image,
219
- 'sketch_image': sketch_image
220
- })
221
 
222
- @app.route('/process_original', methods=['GET', 'POST'])
223
  def process_original():
224
- if request.method == 'POST':
225
- file = request.files['file']
226
-
227
- image = ensure_rgb(Image.open(file.stream))
228
- sotai_image, sketch_image = process_image_as_base64(image, "original")
229
-
230
- return jsonify({
231
- 'sotai_image': sotai_image,
232
- 'sketch_image': sketch_image
233
- })
234
 
235
- @app.route('/process_sketch', methods=['GET', 'POST'])
236
  def process_sketch():
237
- if request.method == 'POST':
238
- file = request.files['file']
239
-
240
- image = ensure_rgb(Image.open(file.stream))
241
- sotai_image, sketch_image = process_image_as_base64(image, "sketch")
242
-
243
- return jsonify({
244
- 'sotai_image': sotai_image,
245
- 'sketch_image': sketch_image
246
- })
247
 
248
  # グローバルエラーハンドラー
249
  @app.errorhandler(Exception)
 
204
  redis_client.decr('connected_clients')
205
 
206
  # Flaskルート
207
+ # ルートパスのGETリクエストに対するハンドラ
208
+ @app.route('/', methods=['GET'])
209
+ def root():
210
+ return jsonify({"status": "ok", "message": "Server is running"}), 200
211
+
212
+ # process_refined のエンドポイント
213
+ @app.route('/process_refined', methods=['POST'])
214
  def process_refined():
215
+ file = request.files['file']
216
+ weight1 = float(request.form.get('weight1', 0.4))
217
+ weight2 = float(request.form.get('weight2', 0.3))
218
+
219
+ image = ensure_rgb(Image.open(file.stream))
220
+ sotai_image, sketch_image = process_image_as_base64(image, "refine", weight1, weight2)
221
+
222
+ return jsonify({
223
+ 'sotai_image': sotai_image,
224
+ 'sketch_image': sketch_image
225
+ })
 
226
 
227
+ @app.route('/process_original', methods=['POST'])
228
  def process_original():
229
+ file = request.files['file']
230
+
231
+ image = ensure_rgb(Image.open(file.stream))
232
+ sotai_image, sketch_image = process_image_as_base64(image, "original")
233
+
234
+ return jsonify({
235
+ 'sotai_image': sotai_image,
236
+ 'sketch_image': sketch_image
237
+ })
 
238
 
239
+ @app.route('/process_sketch', methods=['POST'])
240
  def process_sketch():
241
+ file = request.files['file']
242
+
243
+ image = ensure_rgb(Image.open(file.stream))
244
+ sotai_image, sketch_image = process_image_as_base64(image, "sketch")
245
+
246
+ return jsonify({
247
+ 'sotai_image': sotai_image,
248
+ 'sketch_image': sketch_image
249
+ })
 
250
 
251
  # グローバルエラーハンドラー
252
  @app.errorhandler(Exception)