Spaces:
Running
Running
File size: 2,702 Bytes
f780933 83db025 f780933 83db025 f780933 83db025 78a6f64 f780933 3eb2f44 f780933 83db025 78a6f64 f780933 83db025 f780933 f5528f6 f780933 83db025 f780933 83db025 f780933 83db025 f780933 83db025 f780933 3eb2f44 f780933 83db025 3eb2f44 83db025 f780933 a38437e 83db025 f780933 83db025 f780933 83db025 f780933 3eb2f44 83db025 f780933 83db025 | 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import os
import io
import gradio as gr
from pathlib import Path
from rich.console import Console
# Import your modules
from cli_app.command_handler import handle_command
import cli_app.command_handler as handler
from vector_store.instruction_embedder import embed_analyze_instructions
def terminal_logic(command):
if not command: return "", None
output_buffer = io.StringIO()
temp_console = Console(file=output_buffer, force_terminal=True, width=100, color_system=None)
old_console = getattr(handler, 'console', None)
handler.console = temp_console
try:
result = handle_command(command)
captured = output_buffer.getvalue()
combined = f"{captured}\n{str(result) if result else ''}".strip()
image_path = None
if ".png" in combined:
for word in combined.split():
clean = word.strip(".,![]'\"")
if clean.endswith(".png") and os.path.exists(clean):
image_path = clean
break
return f"```\n{combined}\n```", image_path
except Exception as e:
return f"Error: {str(e)}", None
finally:
handler.console = old_console
def run_space_interface():
embed_analyze_instructions()
# Auto-hydrate
data_dir = Path("data/datasets")
if data_dir.exists():
for file in os.listdir(data_dir):
if file.endswith((".parquet", ".pkl")) and "embeddings" not in file:
try: handler.handle_command(f"load {data_dir / file}")
except: continue
with gr.Blocks(theme="monochrome", analytics_enabled=False) as demo:
gr.Markdown("# 📊 EDA Explorer Terminal")
with gr.Row():
# Markdown is significantly safer than gr.Code for preventing schema crashes
output_box = gr.Markdown(value="```\nTerminal Ready\n```")
plot_output = gr.Image(label="Visual Analysis", type="filepath")
input_box = gr.Textbox(label="Command Line")
gr.Examples(
examples=[["list"], ["NL: show top 10 rows in titanic"], ["NL: average Age in titanic"], ["histogram age in titanic"]],
inputs=input_box
)
# api_name=False is the crucial fix for the "bool is not iterable" crawler error
input_box.submit(
fn=terminal_logic,
inputs=input_box,
outputs=[output_box, plot_output],
api_name=False
)
demo.launch(server_name="0.0.0.0", server_port=7860, show_api=False)
if __name__ == "__main__":
run_space_interface() |