Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
|
| 5 |
+
# Make sure repo folder exists
|
| 6 |
+
if not os.path.exists("storage"):
|
| 7 |
+
os.makedirs("storage")
|
| 8 |
+
|
| 9 |
+
def run_command(cmd):
|
| 10 |
+
try:
|
| 11 |
+
# Run inside storage so data persists during Space lifetime
|
| 12 |
+
result = subprocess.run(
|
| 13 |
+
cmd, shell=True, cwd="storage",
|
| 14 |
+
capture_output=True, text=True
|
| 15 |
+
)
|
| 16 |
+
return result.stdout + result.stderr
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return str(e)
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("## 🚀 Hugging Face Mini Terminal with Persistence")
|
| 22 |
+
cmd = gr.Textbox(label="Enter command", placeholder="e.g. git clone https://github.com/user/repo.git")
|
| 23 |
+
out = gr.Textbox(label="Output")
|
| 24 |
+
run_btn = gr.Button("Run")
|
| 25 |
+
run_btn.click(run_command, inputs=cmd, outputs=out)
|
| 26 |
+
|
| 27 |
+
demo.launch()
|