Spaces:
Sleeping
Sleeping
| 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() | |