mahiatlinux commited on
Commit
0040ae4
1 Parent(s): e08f038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -1,8 +1,35 @@
1
  import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def main():
4
- # Run the command
5
- subprocess.run(["node", "./src/index.js"])
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  if __name__ == "__main__":
8
  main()
 
1
  import subprocess
2
+ import threading
3
+ from http.server import HTTPServer, BaseHTTPRequestHandler
4
+
5
+ class NodeJSRunner(threading.Thread):
6
+ def run(self):
7
+ # Run the Node.js script
8
+ subprocess.run(["node", "./src/index.js"])
9
+
10
+ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
11
+ def do_GET(self):
12
+ self.send_response(200)
13
+ self.send_header('Content-type', 'text/plain')
14
+ self.end_headers()
15
+ self.wfile.write(b'Main Ollama bridge is running!')
16
 
17
  def main():
18
+ # Set server address and port
19
+ server_address = ('0.0.0.0', 7860)
20
+
21
+ # Create an HTTP server
22
+ httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
23
+
24
+ # Start the HTTP server in a separate thread
25
+ http_server_thread = threading.Thread(target=httpd.serve_forever)
26
+ http_server_thread.start()
27
+
28
+ # Start the Node.js script in a separate thread
29
+ nodejs_thread = NodeJSRunner()
30
+ nodejs_thread.start()
31
+
32
+ print('Server and Node.js script started...')
33
 
34
  if __name__ == "__main__":
35
  main()