Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from io import StringIO
|
3 |
import sys
|
4 |
import os
|
5 |
-
import
|
6 |
|
7 |
original_stdout = sys.stdout
|
8 |
sys.stdout = StringIO()
|
@@ -22,12 +22,20 @@ def execute_code(source, token, output_callback):
|
|
22 |
sys.stdout = original_stdout
|
23 |
|
24 |
def exc(source, token):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
app = gr.Interface(
|
33 |
fn=exc,
|
|
|
2 |
from io import StringIO
|
3 |
import sys
|
4 |
import os
|
5 |
+
import multiprocessing
|
6 |
|
7 |
original_stdout = sys.stdout
|
8 |
sys.stdout = StringIO()
|
|
|
22 |
sys.stdout = original_stdout
|
23 |
|
24 |
def exc(source, token):
|
25 |
+
sys.stdout = StringIO()
|
26 |
+
try:
|
27 |
+
if token != os.environ["special_token"]:
|
28 |
+
return ["", ""]
|
29 |
+
else:
|
30 |
+
p = multiprocessing.Process(exec, args=[source])
|
31 |
+
p.start()
|
32 |
+
for i in range(100):
|
33 |
+
console_output = sys.stdout.getvalue().strip()
|
34 |
+
yield ["", console_output]
|
35 |
+
except Exception as e:
|
36 |
+
return ["", f"{e}"]
|
37 |
+
finally:
|
38 |
+
sys.stdout = original_stdoug
|
39 |
|
40 |
app = gr.Interface(
|
41 |
fn=exc,
|