Spaces:
Running
Running
Commit
·
dfa5c67
1
Parent(s):
7a10318
Update app.py
Browse files
app.py
CHANGED
@@ -4,60 +4,25 @@ import subprocess
|
|
4 |
import os
|
5 |
import signal
|
6 |
|
7 |
-
async def take_input(websocket,prompt):
|
8 |
-
await websocket.send(f'input:{prompt}')
|
9 |
-
user_input = await websocket.recv()
|
10 |
-
with open('input.txt', 'w') as f:
|
11 |
-
f.write(user_input )
|
12 |
-
myinput = open('input.txt')
|
13 |
-
return user_input
|
14 |
|
15 |
async def run_code(websocket, path):
|
16 |
try:
|
17 |
# Read the code from the WebSocket connection
|
18 |
code = await websocket.recv()
|
19 |
-
|
20 |
-
# if args:
|
21 |
-
# print(f'>:{args[0]}')
|
22 |
-
# value = input()
|
23 |
-
# return value
|
24 |
-
# else:
|
25 |
-
# print(f'>:')
|
26 |
-
# value = input()
|
27 |
-
# return value"""+'\n'+code.replace("input(", "make_input(")
|
28 |
|
29 |
async with websockets.connect('wss://ramesh-vani-wspython.hf.space') as web:
|
30 |
await web.send(code)
|
31 |
while True:
|
32 |
response = await web.recv()
|
|
|
33 |
await send_message(response)
|
34 |
break
|
35 |
|
36 |
async def send_message(message):
|
37 |
await websocket.send(f'data: {message}')
|
38 |
|
39 |
-
|
40 |
-
# if line.strip().startswith(b">:"):
|
41 |
-
# # if b'input:' in line.strip():
|
42 |
-
# prompt = line.strip()[2:]
|
43 |
-
# user_input = await take_input(websocket,prompt)
|
44 |
-
# process.stdin.write(user_input.encode('utf-8') + b'\n')
|
45 |
-
# await process.stdin.drain()
|
46 |
-
|
47 |
-
# async for line in process.stdout:
|
48 |
-
# await process_input_request(line)
|
49 |
-
# await send_message(line.strip())
|
50 |
-
|
51 |
-
# async for line in process.stderr:
|
52 |
-
# print(f'error:{line.strip()}')
|
53 |
-
# await send_message(f'error:{line.strip()}')
|
54 |
-
|
55 |
-
# return_code = await process.wait()
|
56 |
-
# if return_code == 0:
|
57 |
-
# # await send_message('Code executed successfully')
|
58 |
-
# pass
|
59 |
-
# else:
|
60 |
-
# await send_message(f'error:Execution failed with return code {return_code}')
|
61 |
|
62 |
except Exception as e:
|
63 |
print(f'error: {str(e)}')
|
|
|
4 |
import os
|
5 |
import signal
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
async def run_code(websocket, path):
|
9 |
try:
|
10 |
# Read the code from the WebSocket connection
|
11 |
code = await websocket.recv()
|
12 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
async with websockets.connect('wss://ramesh-vani-wspython.hf.space') as web:
|
15 |
await web.send(code)
|
16 |
while True:
|
17 |
response = await web.recv()
|
18 |
+
print(response)
|
19 |
await send_message(response)
|
20 |
break
|
21 |
|
22 |
async def send_message(message):
|
23 |
await websocket.send(f'data: {message}')
|
24 |
|
25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
except Exception as e:
|
28 |
print(f'error: {str(e)}')
|