monra commited on
Commit
27d38df
1 Parent(s): c05f371

Code improvement

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