Araeynn commited on
Commit
6b0af28
1 Parent(s): e05989c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -24
app.py CHANGED
@@ -2,46 +2,27 @@ import gradio as gr
2
  from io import StringIO
3
  import sys
4
  import os
5
- import multiprocessing
6
 
7
  original_stdout = sys.stdout
8
  sys.stdout = StringIO()
9
 
10
- def execute_code(source, token, output_callback):
11
- sys.stdout = StringIO()
12
- try:
13
- if token != os.environ["special_token"]:
14
- output_callback(["", ""])
15
- else:
16
- exec(source)
17
- console_output = sys.stdout.getvalue().strip()
18
- output_callback([console_output, ""])
19
- except Exception as e:
20
- output_callback(["", f"{e}"])
21
- finally:
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,
42
  inputs=["text", "text"],
43
  outputs=["text", "text"],
44
- live=True
45
  )
46
 
47
- app.launch()
 
2
  from io import StringIO
3
  import sys
4
  import os
 
5
 
6
  original_stdout = sys.stdout
7
  sys.stdout = StringIO()
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def exc(source, token):
10
  sys.stdout = StringIO()
11
  try:
12
  if token != os.environ["special_token"]:
13
  return ["", ""]
14
  else:
15
+ op = exec(source)
16
+ consoleop = sys.stdout.getvalue().strip()
17
+ return [op, consoleop]
 
 
18
  except Exception as e:
19
  return ["", f"{e}"]
20
+ sys.stdout = original_stdout
 
21
 
22
  app = gr.Interface(
23
  fn=exc,
24
  inputs=["text", "text"],
25
  outputs=["text", "text"],
 
26
  )
27
 
28
+ app.launch()