|
1 | | -""" |
2 | | -SpectrumLab 命令行界面 |
3 | | -""" |
4 | | - |
5 | 1 | import argparse |
| 2 | +import sys |
6 | 3 | from typing import Optional, List |
7 | 4 |
|
| 5 | +from .api import run_evaluation |
| 6 | +from spectrumlab.models import ( |
| 7 | + GPT4o, |
| 8 | + Claude_Sonnet_3_5, |
| 9 | + DeepSeek_VL2, |
| 10 | + InternVL, |
| 11 | + Qwen_2_5_VL_32B, |
| 12 | +) |
| 13 | + |
| 14 | +AVAILABLE_MODELS = { |
| 15 | + "gpt4o": GPT4o, |
| 16 | + "claude": Claude_Sonnet_3_5, |
| 17 | + "deepseek": DeepSeek_VL2, |
| 18 | + "internvl": InternVL, |
| 19 | + "qwen-vl": Qwen_2_5_VL_32B, |
| 20 | +} |
| 21 | + |
8 | 22 |
|
9 | 23 | def main(argv: Optional[List[str]] = None) -> int: |
10 | | - """ |
11 | | - SpectrumLab 主命令行入口点 |
12 | | - """ |
13 | 24 | parser = argparse.ArgumentParser( |
14 | | - prog="spectrumlab", description="化学谱学大模型 Benchmark 引擎" |
| 25 | + prog="spectrumlab", |
| 26 | + description="A pioneering unified platform designed to systematize and accelerate deep learning research in spectroscopy", |
| 27 | + ) |
| 28 | + |
| 29 | + parser.add_argument("--version", action="version", version="%(prog)s 0.1.0") |
| 30 | + |
| 31 | + subparsers = parser.add_subparsers(dest="command", help="Available commands") |
| 32 | + |
| 33 | + eval_parser = subparsers.add_parser("eval", help="Run model evaluation") |
| 34 | + |
| 35 | + eval_parser.add_argument( |
| 36 | + "--model", |
| 37 | + "-m", |
| 38 | + required=True, |
| 39 | + choices=list(AVAILABLE_MODELS.keys()), |
| 40 | + help=f"Model name, options: {', '.join(AVAILABLE_MODELS.keys())}", |
| 41 | + ) |
| 42 | + |
| 43 | + eval_parser.add_argument( |
| 44 | + "--level", |
| 45 | + "-l", |
| 46 | + required=True, |
| 47 | + choices=["signal", "perception", "semantic", "generation"], |
| 48 | + help="Evaluation level", |
15 | 49 | ) |
16 | 50 |
|
17 | | - parser.add_argument("--version", action="version", version="%(prog)s 0.0.1") |
| 51 | + eval_parser.add_argument( |
| 52 | + "--subcategories", |
| 53 | + "-s", |
| 54 | + nargs="*", |
| 55 | + help="Specify subcategories (optional, default: all)", |
| 56 | + ) |
18 | 57 |
|
19 | | - subparsers = parser.add_subparsers(dest="command", help="可用命令") |
| 58 | + eval_parser.add_argument( |
| 59 | + "--data-path", "-d", default="./data", help="Data path (default: ./data)" |
| 60 | + ) |
| 61 | + |
| 62 | + eval_parser.add_argument( |
| 63 | + "--output", "-o", default="./results", help="Output path (default: ./results)" |
| 64 | + ) |
20 | 65 |
|
21 | | - # 示例子命令 |
22 | | - eval_parser = subparsers.add_parser("eval", help="运行评估") |
23 | | - eval_parser.add_argument("--model", help="模型名称", required=True) |
24 | | - eval_parser.add_argument("--dataset", help="数据集名称", required=True) |
| 66 | + eval_parser.add_argument( |
| 67 | + "--max-length", type=int, default=512, help="Max output length (default: 512)" |
| 68 | + ) |
25 | 69 |
|
26 | 70 | args = parser.parse_args(argv) |
27 | 71 |
|
28 | 72 | if args.command == "eval": |
29 | | - print(f"正在评估模型: {args.model}") |
30 | | - print(f"使用数据集: {args.dataset}") |
31 | | - return 0 |
| 73 | + try: |
| 74 | + # Initialize the model |
| 75 | + if args.model not in AVAILABLE_MODELS: |
| 76 | + available = ", ".join(AVAILABLE_MODELS.keys()) |
| 77 | + raise ValueError( |
| 78 | + f"Unsupported model: {args.model}. Available: {available}" |
| 79 | + ) |
| 80 | + |
| 81 | + model_class = AVAILABLE_MODELS[args.model] |
| 82 | + model_instance = model_class() |
| 83 | + |
| 84 | + results = run_evaluation( |
| 85 | + model=model_instance, |
| 86 | + level=args.level, |
| 87 | + subcategories=args.subcategories, |
| 88 | + data_path=args.data_path, |
| 89 | + save_path=args.output, |
| 90 | + max_out_len=args.max_length, |
| 91 | + ) |
| 92 | + |
| 93 | + print("\n" + "=" * 50) |
| 94 | + print("📊 Evaluation Results") |
| 95 | + print("=" * 50) |
| 96 | + |
| 97 | + if "error" in results: |
| 98 | + print(f"❌ Evaluation failed: {results['error']}") |
| 99 | + return 1 |
| 100 | + |
| 101 | + metrics = results.get("metrics", {}) |
| 102 | + overall = metrics.get("overall", {}) |
| 103 | + |
| 104 | + print("✅ Evaluation completed!") |
| 105 | + print(f"📈 Overall accuracy: {overall.get('accuracy', 0):.2f}%") |
| 106 | + print(f"✅ Correct answers: {overall.get('correct', 0)}") |
| 107 | + print(f"📝 Total questions: {overall.get('total', 0)}") |
| 108 | + |
| 109 | + subcategory_metrics = metrics.get("subcategory_metrics", {}) |
| 110 | + if subcategory_metrics: |
| 111 | + print("\n📋 Subcategory details:") |
| 112 | + for subcategory, sub_metrics in subcategory_metrics.items(): |
| 113 | + acc = sub_metrics.get("accuracy", 0) |
| 114 | + correct = sub_metrics.get("correct", 0) |
| 115 | + total = sub_metrics.get("total", 0) |
| 116 | + print(f" {subcategory}: {acc:.2f}% ({correct}/{total})") |
| 117 | + |
| 118 | + print(f"\n💾 Results saved to: {args.output}") |
| 119 | + return 0 |
| 120 | + |
| 121 | + except Exception as e: |
| 122 | + print(f"❌ Evaluation failed: {e}") |
| 123 | + return 1 |
| 124 | + |
32 | 125 | elif args.command is None: |
33 | 126 | parser.print_help() |
34 | 127 | return 0 |
35 | | - |
36 | | - return 0 |
| 128 | + else: |
| 129 | + print(f"❌ Unknown command: {args.command}") |
| 130 | + parser.print_help() |
| 131 | + return 1 |
37 | 132 |
|
38 | 133 |
|
39 | 134 | if __name__ == "__main__": |
40 | | - exit(main()) |
| 135 | + sys.exit(main()) |
0 commit comments