Load Kronos model
()
| 625 | |
| 626 | @app.route('/api/load-model', methods=['POST']) |
| 627 | def load_model(): |
| 628 | """Load Kronos model""" |
| 629 | global tokenizer, model, predictor |
| 630 | |
| 631 | try: |
| 632 | if not MODEL_AVAILABLE: |
| 633 | return jsonify({'error': 'Kronos model library not available'}), 400 |
| 634 | |
| 635 | data = request.get_json() |
| 636 | model_key = data.get('model_key', 'kronos-small') |
| 637 | device = data.get('device', 'cpu') |
| 638 | |
| 639 | if model_key not in AVAILABLE_MODELS: |
| 640 | return jsonify({'error': f'Unsupported model: {model_key}'}), 400 |
| 641 | |
| 642 | model_config = AVAILABLE_MODELS[model_key] |
| 643 | |
| 644 | # Load tokenizer and model |
| 645 | tokenizer = KronosTokenizer.from_pretrained(model_config['tokenizer_id']) |
| 646 | model = Kronos.from_pretrained(model_config['model_id']) |
| 647 | |
| 648 | # Create predictor |
| 649 | predictor = KronosPredictor(model, tokenizer, device=device, max_context=model_config['context_length']) |
| 650 | |
| 651 | return jsonify({ |
| 652 | 'success': True, |
| 653 | 'message': f'Model loaded successfully: {model_config["name"]} ({model_config["params"]}) on {device}', |
| 654 | 'model_info': { |
| 655 | 'name': model_config['name'], |
| 656 | 'params': model_config['params'], |
| 657 | 'context_length': model_config['context_length'], |
| 658 | 'description': model_config['description'] |
| 659 | } |
| 660 | }) |
| 661 | |
| 662 | except Exception as e: |
| 663 | return jsonify({'error': f'Model loading failed: {str(e)}'}), 500 |
| 664 | |
| 665 | @app.route('/api/available-models') |
| 666 | def get_available_models(): |
nothing calls this directly
no test coverage detected