monra commited on
Commit
b5d3cae
1 Parent(s): 8a8fe1d

Adds auto-initialization to the GPT-4 model API

Browse files
Files changed (1) hide show
  1. run.py +13 -1
run.py CHANGED
@@ -7,9 +7,11 @@ from server.backend import Backend_Api
7
  from json import load
8
 
9
  if __name__ == '__main__':
 
10
  config = load(open('config.json', 'r'))
11
  site_config = config['site_config']
12
 
 
13
  site = Website(app)
14
  for route in site.routes:
15
  app.add_url_rule(
@@ -18,6 +20,7 @@ if __name__ == '__main__':
18
  methods=site.routes[route]['methods'],
19
  )
20
 
 
21
  backend_api = Backend_Api(app, config)
22
  for route in backend_api.routes:
23
  app.add_url_rule(
@@ -26,11 +29,20 @@ if __name__ == '__main__':
26
  methods=backend_api.routes[route]['methods'],
27
  )
28
 
 
29
  api_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "apiGPT4")
30
- api_process = subprocess.Popen(["npm", "run", "start"], cwd=api_directory, shell=True)
31
 
 
 
 
 
 
 
 
 
32
  print(f"Running on port {site_config['port']}")
33
  app.run(**site_config)
34
  print(f"Closing port {site_config['port']}")
35
 
 
36
  api_process.terminate()
 
7
  from json import load
8
 
9
  if __name__ == '__main__':
10
+ # Load configuration from config.json
11
  config = load(open('config.json', 'r'))
12
  site_config = config['site_config']
13
 
14
+ # Set up the website routes
15
  site = Website(app)
16
  for route in site.routes:
17
  app.add_url_rule(
 
20
  methods=site.routes[route]['methods'],
21
  )
22
 
23
+ # Set up the backend API routes
24
  backend_api = Backend_Api(app, config)
25
  for route in backend_api.routes:
26
  app.add_url_rule(
 
29
  methods=backend_api.routes[route]['methods'],
30
  )
31
 
32
+ # Get the API directory path
33
  api_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "apiGPT4")
 
34
 
35
+ # Install the API dependencies using yarn
36
+ install_dependencies = subprocess.Popen(["yarn"], cwd=api_directory, shell=True)
37
+ install_dependencies.wait()
38
+
39
+ # Start the API process using yarn start
40
+ api_process = subprocess.Popen(["yarn", "start"], cwd=api_directory, shell=True)
41
+
42
+ # Run the Flask server
43
  print(f"Running on port {site_config['port']}")
44
  app.run(**site_config)
45
  print(f"Closing port {site_config['port']}")
46
 
47
+ # Terminate the API process when the Flask server is closed
48
  api_process.terminate()