Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from builtin_commands import handle_builtin_commands
|
| 3 |
+
from external_commands import run_external_command
|
| 4 |
+
from display import clear_and_setup
|
| 5 |
+
|
| 6 |
+
# Capture outputs instead of printing
|
| 7 |
+
import io
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
def run_command(command: str):
|
| 11 |
+
if not command.strip():
|
| 12 |
+
return ""
|
| 13 |
+
|
| 14 |
+
# Redirect stdout
|
| 15 |
+
buffer = io.StringIO()
|
| 16 |
+
sys.stdout = buffer
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
command_parts = command.strip().split()
|
| 20 |
+
|
| 21 |
+
if command.lower() == "exit":
|
| 22 |
+
print("👋 Session ended.")
|
| 23 |
+
elif handle_builtin_commands(command_parts):
|
| 24 |
+
pass
|
| 25 |
+
else:
|
| 26 |
+
run_external_command(command_parts)
|
| 27 |
+
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error: {e}")
|
| 30 |
+
|
| 31 |
+
finally:
|
| 32 |
+
sys.stdout = sys.__stdout__
|
| 33 |
+
|
| 34 |
+
return buffer.getvalue()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# Codic — AI Coding Terminal (Web Demo)")
|
| 39 |
+
gr.Markdown("Natural language → code actions")
|
| 40 |
+
|
| 41 |
+
input_box = gr.Textbox(
|
| 42 |
+
label="Command",
|
| 43 |
+
placeholder="create project my_app",
|
| 44 |
+
lines=2
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
output_box = gr.Textbox(
|
| 48 |
+
label="Output",
|
| 49 |
+
lines=12
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
input_box.submit(run_command, input_box, output_box)
|
| 53 |
+
|
| 54 |
+
demo.launch()
|