Spaces:
Running
Running
Commit ·
b617b0d
1
Parent(s): 6fc688e
command fix
Browse files
app.py
CHANGED
|
@@ -53,48 +53,32 @@ def run_cli():
|
|
| 53 |
def run_space_interface():
|
| 54 |
embed_analyze_instructions()
|
| 55 |
|
| 56 |
-
def
|
| 57 |
-
# 1. Create a "Fake" terminal to catch the output
|
| 58 |
output_buffer = io.StringIO()
|
| 59 |
-
#
|
| 60 |
-
temp_console = Console(file=output_buffer, force_terminal=True, width=100, color_system=
|
| 61 |
|
| 62 |
-
# 2. Access the handler's console
|
| 63 |
import cli_app.command_handler as handler
|
| 64 |
-
|
| 65 |
-
# Save the original to restore it later
|
| 66 |
old_console = getattr(handler, 'console', None)
|
| 67 |
handler.console = temp_console
|
| 68 |
|
| 69 |
try:
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
# 4. Get the captured "Rich" text
|
| 74 |
-
captured_output = output_buffer.getvalue()
|
| 75 |
-
|
| 76 |
-
# 5. Clean logic for the UI
|
| 77 |
-
if result == "exit":
|
| 78 |
-
return "Session ended. Refresh to restart."
|
| 79 |
-
|
| 80 |
-
# If the command printed a table, result is likely ""
|
| 81 |
-
# so we return the captured buffer.
|
| 82 |
-
return captured_output if not result else f"{captured_output}\n{result}"
|
| 83 |
-
|
| 84 |
except Exception as e:
|
| 85 |
return f"Error: {str(e)}"
|
| 86 |
finally:
|
| 87 |
-
# 6. Restore original console
|
| 88 |
if old_console:
|
| 89 |
handler.console = old_console
|
| 90 |
|
| 91 |
-
# Using
|
| 92 |
-
demo = gr.
|
| 93 |
-
fn=
|
|
|
|
|
|
|
| 94 |
title="📊 EDA Explorer Terminal",
|
| 95 |
-
|
| 96 |
-
theme="soft", # Looks clean for recruiters
|
| 97 |
-
examples=["help", "list", "analyze"]
|
| 98 |
)
|
| 99 |
|
| 100 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 53 |
def run_space_interface():
|
| 54 |
embed_analyze_instructions()
|
| 55 |
|
| 56 |
+
def terminal_logic(command):
|
|
|
|
| 57 |
output_buffer = io.StringIO()
|
| 58 |
+
# No color_system means no "gibberish" ANSI codes, just clean text tables
|
| 59 |
+
temp_console = Console(file=output_buffer, force_terminal=True, width=100, color_system=None)
|
| 60 |
|
|
|
|
| 61 |
import cli_app.command_handler as handler
|
|
|
|
|
|
|
| 62 |
old_console = getattr(handler, 'console', None)
|
| 63 |
handler.console = temp_console
|
| 64 |
|
| 65 |
try:
|
| 66 |
+
result = handler.handle_command(command)
|
| 67 |
+
captured = output_buffer.getvalue()
|
| 68 |
+
return captured if not result else f"{captured}\n{result}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
except Exception as e:
|
| 70 |
return f"Error: {str(e)}"
|
| 71 |
finally:
|
|
|
|
| 72 |
if old_console:
|
| 73 |
handler.console = old_console
|
| 74 |
|
| 75 |
+
# Using Interface + Code block instead of ChatInterface
|
| 76 |
+
demo = gr.Interface(
|
| 77 |
+
fn=terminal_logic,
|
| 78 |
+
inputs=gr.Textbox(label="Terminal Input", placeholder="Type command (e.g., 'help' or 'list')..."),
|
| 79 |
+
outputs=gr.Code(label="Terminal Output", language="markdown"), # language=markdown helps with table spacing
|
| 80 |
title="📊 EDA Explorer Terminal",
|
| 81 |
+
allow_flagging="never"
|
|
|
|
|
|
|
| 82 |
)
|
| 83 |
|
| 84 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|