Kiran5 commited on
Commit
001c169
·
1 Parent(s): 3d2dce1

Add application file

Browse files
Files changed (1) hide show
  1. main.py +11 -22
main.py CHANGED
@@ -10,36 +10,25 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
  import json
11
  from werkzeug.exceptions import HTTPException, UnprocessableEntity, InternalServerError
12
  from flask import Flask
13
- from router.router import app # Ensure this is a Flask Blueprint
14
  from flask_swagger_ui import get_swaggerui_blueprint
15
  from flask_cors import CORS
16
- from dotenv import load_dotenv
17
  import os
18
-
19
  load_dotenv()
20
 
21
- # Initialize request_id_var properly, if necessary
22
- # For example, you can set it as a simple string or initialize your logger here.
23
- # request_id_var.set("StartUp") # Comment out or initialize properly
24
-
25
- SWAGGER_URL = '/rai/v1/moderations/docs'
26
- API_URL = '/static/metadata.json'
27
-
28
- swaggerui_blueprint = get_swaggerui_blueprint(
29
- SWAGGER_URL, API_URL,
30
- config={'app_name': "Infosys Responsible AI - Moderation"}
31
- )
32
-
33
- # Create Flask app instance
34
  app1 = Flask(__name__)
35
 
36
- # Register blueprints
37
- app1.register_blueprint(app)
 
 
38
  app1.register_blueprint(swaggerui_blueprint)
39
 
 
40
  CORS(app1)
41
 
42
- # Error handlers
43
  @app1.errorhandler(HTTPException)
44
  def handle_exception(e):
45
  response = e.get_response()
@@ -73,10 +62,10 @@ def internal_server_error_handler(exc):
73
  response.content_type = "application/json"
74
  return response
75
 
76
- # Start Flask server
77
  if __name__ == "__main__":
78
- # Make sure the logger is not trying to write to non-writable directories
79
- app1.run(host='0.0.0.0', port=int(os.getenv("PORT", 7860)), debug=False)
80
 
81
 
82
 
 
10
  import json
11
  from werkzeug.exceptions import HTTPException, UnprocessableEntity, InternalServerError
12
  from flask import Flask
 
13
  from flask_swagger_ui import get_swaggerui_blueprint
14
  from flask_cors import CORS
15
+ from waitress import serve
16
  import os
17
+ from dotenv import load_dotenv
18
  load_dotenv()
19
 
20
+ # Flask app setup
 
 
 
 
 
 
 
 
 
 
 
 
21
  app1 = Flask(__name__)
22
 
23
+ # Swagger UI setup
24
+ SWAGGER_URL = '/rai/v1/moderations/docs'
25
+ API_URL = '/static/metadata.json'
26
+ swaggerui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL, config={'app_name': "Infosys Responsible AI - Moderation"})
27
  app1.register_blueprint(swaggerui_blueprint)
28
 
29
+ # CORS and error handling setup
30
  CORS(app1)
31
 
 
32
  @app1.errorhandler(HTTPException)
33
  def handle_exception(e):
34
  response = e.get_response()
 
62
  response.content_type = "application/json"
63
  return response
64
 
65
+ # Use Waitress for production server
66
  if __name__ == "__main__":
67
+ serve(app1, host="0.0.0.0", port=7860)
68
+
69
 
70
 
71