ws-bridge / app.py
Ramesh-vani's picture
Update app.py
cb65892
raw
history blame
977 Bytes
import asyncio
import websockets
import subprocess
import os
import signal
async def run_code(websocket, path):
try:
# Read the code from the WebSocket connection
code = await websocket.recv()
print(code)
async with websockets.connect('wss://ramesh-vani-wspython.hf.space') as web:
await web.send(code)
print("Code sent to external WebSocket server.")
while True:
response = await web.recv()
print("Received response:", response)
await send_message(response)
break
async def send_message(message):
await websocket.send(f'data: {message}')
except Exception as e:
print(f'error: {str(e)}')
await websocket.send(f'error: {str(e)}')
start_server = websockets.serve(run_code, "0.0.0.0", 7860)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()