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