Spaces:
Sleeping
Sleeping
File size: 4,503 Bytes
9281fab |
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
"""
Command-Line Interface for CoDA.
Provides a CLI for running the CoDA visualization pipeline locally.
"""
import argparse
import logging
import sys
from pathlib import Path
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
def main():
"""Main entry point for the CLI."""
parser = argparse.ArgumentParser(
description="CoDA - Collaborative Data Visualization Agents",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python main.py --query "Show sales trends" --data sales.csv
python main.py -q "Bar chart of categories" -d data.xlsx
python main.py --query "Scatter plot" --data file1.csv file2.csv
"""
)
parser.add_argument(
"-q", "--query",
type=str,
required=True,
help="Natural language visualization query"
)
parser.add_argument(
"-d", "--data",
type=str,
nargs="+",
required=True,
help="Path(s) to data file(s)"
)
parser.add_argument(
"-o", "--output",
type=str,
default="outputs",
help="Output directory for visualizations (default: outputs)"
)
parser.add_argument(
"--max-iterations",
type=int,
default=3,
help="Maximum refinement iterations (default: 3)"
)
parser.add_argument(
"--min-score",
type=float,
default=7.0,
help="Minimum quality score threshold (default: 7.0)"
)
parser.add_argument(
"-v", "--verbose",
action="store_true",
help="Enable verbose logging"
)
args = parser.parse_args()
if args.verbose:
logging.getLogger().setLevel(logging.DEBUG)
for path in args.data:
if not Path(path).exists():
logger.error(f"Data file not found: {path}")
sys.exit(1)
try:
from coda.config import Config, ExecutionConfig, QualityThresholds
from coda.orchestrator import CodaOrchestrator
except ImportError as e:
logger.error(f"Failed to import CoDA modules: {e}")
logger.error("Make sure you have installed all dependencies: pip install -r requirements.txt")
sys.exit(1)
try:
config = Config(
execution=ExecutionConfig(
max_refinement_iterations=args.max_iterations,
output_directory=args.output,
),
quality=QualityThresholds(
minimum_overall_score=args.min_score,
),
)
except ValueError as e:
logger.error(f"Configuration error: {e}")
sys.exit(1)
def progress_callback(status: str, progress: float):
bar_length = 30
filled = int(bar_length * progress)
bar = "β" * filled + "β" * (bar_length - filled)
print(f"\r[{bar}] {progress:.0%} - {status}", end="", flush=True)
if progress >= 1.0:
print()
print(f"\n{'='*60}")
print("CoDA - Collaborative Data Visualization Agents")
print(f"{'='*60}\n")
print(f"Query: {args.query}")
print(f"Data: {', '.join(args.data)}")
print(f"Output: {args.output}/")
print()
orchestrator = CodaOrchestrator(
config=config,
progress_callback=progress_callback,
)
result = orchestrator.run(
query=args.query,
data_paths=args.data,
)
print()
print(f"{'='*60}")
print("Results")
print(f"{'='*60}\n")
if result.success:
print(f"β
Visualization generated successfully!")
print(f"π Output: {result.output_file}")
print(f"π Iterations: {result.iterations}")
if result.scores:
print(f"\nπ Quality Scores:")
for key, value in result.scores.items():
emoji = "π’" if value >= 7 else "π‘" if value >= 5 else "π΄"
print(f" {key.title()}: {emoji} {value:.1f}/10")
if result.evaluation and result.evaluation.strengths:
print(f"\nπͺ Strengths:")
for s in result.evaluation.strengths[:3]:
print(f" β’ {s}")
else:
print(f"β Visualization failed!")
if result.error:
print(f" Error: {result.error}")
sys.exit(1)
print()
if __name__ == "__main__":
main()
|