Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,14 +32,15 @@ def run_code_with_inputs(code: str, inputs: str) -> str:
|
|
| 32 |
input_data = inputs.replace("\\n", "\n")
|
| 33 |
|
| 34 |
processes, outputs, errors = [], [], []
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
processes.append(subprocess.run(
|
| 45 |
["fpc", file_path.removesuffix('.pseudo')+'.pas'],
|
|
@@ -81,14 +82,14 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
| 81 |
gr.Interface(
|
| 82 |
fn=run_code_with_inputs,
|
| 83 |
inputs=[
|
| 84 |
-
gr.Code(label="Pseudocode",
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
],
|
| 89 |
outputs=gr.Code(
|
| 90 |
label="Program Output",
|
| 91 |
-
lines=20,
|
| 92 |
value="",
|
| 93 |
elem_id="output-box",
|
| 94 |
language=None
|
|
|
|
| 32 |
input_data = inputs.replace("\\n", "\n")
|
| 33 |
|
| 34 |
processes, outputs, errors = [], [], []
|
| 35 |
+
try:
|
| 36 |
+
processes.append(subprocess.run(
|
| 37 |
+
["./pseudocode", file_path, pseudokey, '--echo-inputs'],
|
| 38 |
+
text=True,
|
| 39 |
+
capture_output=True,
|
| 40 |
+
timeout=10
|
| 41 |
+
))
|
| 42 |
+
outputs.append(processes[-1].stdout)
|
| 43 |
+
except: pass
|
| 44 |
|
| 45 |
processes.append(subprocess.run(
|
| 46 |
["fpc", file_path.removesuffix('.pseudo')+'.pas'],
|
|
|
|
| 82 |
gr.Interface(
|
| 83 |
fn=run_code_with_inputs,
|
| 84 |
inputs=[
|
| 85 |
+
gr.Code(label="Pseudocode", language="typescript", value="""DECLARE yourname: STRING
|
| 86 |
+
OUTPUT "What is your name?"
|
| 87 |
+
INPUT yourname
|
| 88 |
+
OUTPUT "Hello, ",yourname,'!' """),
|
| 89 |
+
gr.Code(label="User Inputs", value='Alice\nBob', language=None, elem_id="input-box"),
|
| 90 |
],
|
| 91 |
outputs=gr.Code(
|
| 92 |
label="Program Output",
|
|
|
|
| 93 |
value="",
|
| 94 |
elem_id="output-box",
|
| 95 |
language=None
|