Petermoyano commited on
Commit
4c7c2a7
·
1 Parent(s): 1da03ca

Add request import

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -1,22 +1,28 @@
1
- from flask import Flask
 
2
 
3
  app = Flask(__name__)
4
 
 
 
 
5
  @app.route('/')
6
  def hello_world():
7
  return 'Hello, World!'
8
 
9
  @app.route('/run/predict', methods=['POST'])
10
  def predict():
11
- data = request.json
12
- # Process the input data and generate a response
13
- # For demonstration, we'll just echo the input data
14
- response = {
15
- "data": data
16
- }
17
- return jsonify(response)
 
 
 
18
 
19
  if __name__ == '__main__':
20
  from os import environ
21
- app.run(host='0.0.0.0', port=int(environ.get('PORT', 5000)))
22
-
 
1
+ from flask import Flask, request, jsonify
2
+ import logging
3
 
4
  app = Flask(__name__)
5
 
6
+ # Configure logging
7
+ logging.basicConfig(level=logging.DEBUG)
8
+
9
  @app.route('/')
10
  def hello_world():
11
  return 'Hello, World!'
12
 
13
  @app.route('/run/predict', methods=['POST'])
14
  def predict():
15
+ try:
16
+ data = request.json
17
+ app.logger.debug(f"Received data: {data}")
18
+ response = {
19
+ "data": data
20
+ }
21
+ return jsonify(response)
22
+ except Exception as e:
23
+ app.logger.error(f"Error processing request: {e}")
24
+ return jsonify({"error": "An error occurred"}), 500
25
 
26
  if __name__ == '__main__':
27
  from os import environ
28
+ app.run(host='0.0.0.0', port=int(environ.get('PORT', 5000)))