ProfessionalMario commited on
Commit
b617b0d
·
1 Parent(s): 6fc688e

command fix

Browse files
Files changed (1) hide show
  1. app.py +12 -28
app.py CHANGED
@@ -53,48 +53,32 @@ def run_cli():
53
  def run_space_interface():
54
  embed_analyze_instructions()
55
 
56
- def chat_response(message, history):
57
- # 1. Create a "Fake" terminal to catch the output
58
  output_buffer = io.StringIO()
59
- # We use legacy_windows=False to ensure clean formatting on Linux servers
60
- temp_console = Console(file=output_buffer, force_terminal=True, width=100, color_system="truecolor")
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
- # 3. Run the command
71
- result = handler.handle_command(message)
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 ChatInterface for that modern terminal look
92
- demo = gr.ChatInterface(
93
- fn=chat_response,
 
 
94
  title="📊 EDA Explorer Terminal",
95
- description="Interactive CLI-style data analysis. Start by typing 'help' or 'load <url>'.",
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)