| | | 1 | | using System; |
| | | 2 | | using System.IO; |
| | | 3 | | using System.Threading; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | |
| | | 6 | | namespace InferenceEngine.Core.ModelProviders |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Model provider for locally stored model files. |
| | | 10 | | /// Validates that the file exists but does not perform any network operations. |
| | | 11 | | /// </summary> |
| | | 12 | | public class LocalModelProvider : IModelProvider |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// The model file path (absolute or relative). |
| | | 16 | | /// </summary> |
| | 59 | 17 | | public string ModelPath { get; } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Creates a provider for a local model file. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="modelPath">Absolute or relative path to the .onnx model file</param> |
| | 83 | 23 | | public LocalModelProvider(string modelPath) |
| | | 24 | | { |
| | 83 | 25 | | ModelPath = modelPath ?? throw new ArgumentNullException(nameof(modelPath)); |
| | 82 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | public Task<string> GetModelPathAsync(CancellationToken cancellationToken = default) |
| | | 30 | | { |
| | | 31 | | // Resolve relative paths to absolute |
| | 56 | 32 | | var fullPath = Path.GetFullPath(ModelPath); |
| | | 33 | | |
| | 56 | 34 | | if (!File.Exists(fullPath)) |
| | | 35 | | { |
| | 1 | 36 | | throw new FileNotFoundException($"Model file not found: {fullPath}", fullPath); |
| | | 37 | | } |
| | | 38 | | |
| | 55 | 39 | | return Task.FromResult(fullPath); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | } |