Spaces:
Running
Running
File size: 894 Bytes
d2db5a7 7a10318 d2db5a7 7a10318 02b6e08 dfa5c67 7a10318 26bfbb3 7a10318 dfa5c67 7a10318 dfa5c67 7a10318 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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)
while True:
response = await web.recv()
print(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() |