Spaces:
Running
on
Zero
Running
on
Zero
flask root('/')のgetを実装./process_refinedをendpointを分ける
Browse files
app.py
CHANGED
@@ -204,46 +204,49 @@ def handle_disconnect():
|
|
204 |
redis_client.decr('connected_clients')
|
205 |
|
206 |
# Flaskルート
|
207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
def process_refined():
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
})
|
221 |
|
222 |
-
@app.route('/process_original', methods=['
|
223 |
def process_original():
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
})
|
234 |
|
235 |
-
@app.route('/process_sketch', methods=['
|
236 |
def process_sketch():
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
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)
|