Name108 commited on
Commit
e021baf
·
verified ·
1 Parent(s): 319df4b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import http.server
2
+ import socketserver
3
+ import os
4
+ import subprocess
5
+ import threading
6
+ import time
7
+
8
+ # Define the port for the public-facing HTTP server
9
+ PORT = 7860
10
+
11
+ # The handler for the web server
12
+ class MyHandler(http.server.SimpleHTTPRequestHandler):
13
+ def do_GET(self):
14
+ # Serve client.html when the root URL is requested
15
+ if self.path == '/':
16
+ self.path = '/client.html'
17
+ return http.server.SimpleHTTPRequestHandler.do_GET(self)
18
+
19
+ # Function to run EchoAudio.py in a separate thread
20
+ def run_echo_audio():
21
+ print("Starting EchoAudio.py...")
22
+ # This runs the script as a subprocess
23
+ subprocess.run(["python", "EchoAudio.py"])
24
+
25
+ if __name__ == "__main__":
26
+ # Start the EchoAudio.py script in a new thread
27
+ thread = threading.Thread(target=run_echo_audio)
28
+ thread.start()
29
+
30
+ # Wait a moment for EchoAudio.py to start up
31
+ time.sleep(5)
32
+
33
+ # Set the directory to serve files from (e.g., where client.html is)
34
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
35
+
36
+ # Start the web server on the public port
37
+ with socketserver.TCPServer(("", PORT), MyHandler) as httpd:
38
+ print("Serving client.html on port", PORT)
39
+ httpd.serve_forever()