Spaces:
Paused
Paused
import subprocess | |
import threading | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
class NodeJSRunner(threading.Thread): | |
def run(self): | |
# Run the Node.js script | |
subprocess.run(["node", "./src/index.js"]) | |
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'text/plain') | |
self.end_headers() | |
self.wfile.write(b'Main Ollama bridge is running!') | |
def main(): | |
# Set server address and port | |
server_address = ('0.0.0.0', 7860) | |
# Create an HTTP server | |
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler) | |
# Start the HTTP server in a separate thread | |
http_server_thread = threading.Thread(target=httpd.serve_forever) | |
http_server_thread.start() | |
# Start the Node.js script in a separate thread | |
nodejs_thread = NodeJSRunner() | |
nodejs_thread.start() | |
print('Server and Node.js script started...') | |
if __name__ == "__main__": | |
main() | |