Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import io
|
| 3 |
import contextlib
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def execute_python_code(code):
|
| 6 |
# Capture the output of the code execution
|
|
@@ -16,18 +19,52 @@ def execute_python_code(code):
|
|
| 16 |
except Exception as e:
|
| 17 |
return f"Error: {str(e)}"
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import io
|
| 3 |
import contextlib
|
| 4 |
+
import platform
|
| 5 |
+
import psutil
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
def execute_python_code(code):
|
| 9 |
# Capture the output of the code execution
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
return f"Error: {str(e)}"
|
| 21 |
|
| 22 |
+
def get_system_info():
|
| 23 |
+
# Get system information
|
| 24 |
+
info = {
|
| 25 |
+
"System": platform.system(),
|
| 26 |
+
"Node Name": platform.node(),
|
| 27 |
+
"Release": platform.release(),
|
| 28 |
+
"Version": platform.version(),
|
| 29 |
+
"Machine": platform.machine(),
|
| 30 |
+
"Processor": platform.processor(),
|
| 31 |
+
"CPU Cores": psutil.cpu_count(logical=False),
|
| 32 |
+
"Logical CPUs": psutil.cpu_count(logical=True),
|
| 33 |
+
"RAM": f"{round(psutil.virtual_memory().total / (1024**3), 2)} GB",
|
| 34 |
+
"RAM Used": f"{round(psutil.virtual_memory().used / (1024**3), 2)} GB",
|
| 35 |
+
"RAM Free": f"{round(psutil.virtual_memory().free / (1024**3), 2)} GB",
|
| 36 |
+
"Disk Usage": f"{psutil.disk_usage('/').percent}%",
|
| 37 |
+
"Disk Total": f"{round(psutil.disk_usage('/').total / (1024**3), 2)} GB",
|
| 38 |
+
"Disk Free": f"{round(psutil.disk_usage('/').free / (1024**3), 2)} GB",
|
| 39 |
+
"Python Version": platform.python_version(),
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
formatted_info = "\n".join([f"{k}: {v}" for k, v in info.items()])
|
| 43 |
+
return formatted_info
|
| 44 |
+
|
| 45 |
+
with gr.Blocks() as demo:
|
| 46 |
+
gr.Markdown("# Python Code Executor")
|
| 47 |
+
gr.Markdown("Enter Python code and see the execution results. Note: This executes code in a limited environment.")
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
code_input = gr.Textbox(label="Python Code", lines=10,
|
| 52 |
+
placeholder="Enter your Python code here...")
|
| 53 |
+
execute_btn = gr.Button("Execute Code")
|
| 54 |
+
with gr.Column():
|
| 55 |
+
output = gr.Textbox(label="Execution Result", lines=10)
|
| 56 |
+
sys_info_btn = gr.Button("Show System Info")
|
| 57 |
+
|
| 58 |
+
gr.Examples(
|
| 59 |
+
examples=[
|
| 60 |
+
["print('Hello, World!')"],
|
| 61 |
+
["for i in range(5):\n print(i)"],
|
| 62 |
+
["def square(x):\n return x*x\n\nprint(square(5))"]
|
| 63 |
+
],
|
| 64 |
+
inputs=code_input
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
execute_btn.click(fn=execute_python_code, inputs=code_input, outputs=output)
|
| 68 |
+
sys_info_btn.click(fn=get_system_info, inputs=None, outputs=output)
|
| 69 |
|
| 70 |
+
demo.launch()
|