wsl support
This commit is contained in:
@@ -8,6 +8,7 @@ public class CSharpDataTransferHTTP
|
||||
private readonly HttpClient _client;
|
||||
private readonly CancellationTokenSource _pingCts = new();
|
||||
private readonly Thread _pingThread;
|
||||
private readonly object _lock = new();
|
||||
|
||||
public CSharpDataTransferHTTP()
|
||||
{
|
||||
@@ -15,22 +16,17 @@ public class CSharpDataTransferHTTP
|
||||
{
|
||||
PooledConnectionIdleTimeout = TimeSpan.FromSeconds(10),
|
||||
MaxConnectionsPerServer = 100
|
||||
|
||||
|
||||
|
||||
};
|
||||
_client = new HttpClient(handler)
|
||||
{
|
||||
// i've added this
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
ExpectContinue = false
|
||||
}
|
||||
};
|
||||
_api = new PythonModelAPI("http://localhost:8000",_client);
|
||||
_api = new PythonModelAPI("http://localhost:8000", _client);
|
||||
_pingThread = new Thread(PingLoop) { IsBackground = true };
|
||||
_pingThread.Start();
|
||||
|
||||
}
|
||||
|
||||
private void PingLoop()
|
||||
@@ -51,38 +47,40 @@ public class CSharpDataTransferHTTP
|
||||
|
||||
public void LoadModel(string path, string modelName)
|
||||
{
|
||||
_api.LoadModelAsync(new LoadModelIn()
|
||||
lock (_lock)
|
||||
{
|
||||
Name = modelName,
|
||||
Path = Path.GetFileName(path)
|
||||
}).Wait();
|
||||
_api.LoadModelAsync(new LoadModelIn()
|
||||
{
|
||||
Name = modelName,
|
||||
Path = Path.GetFileName(path)
|
||||
}).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivateModel(string modelName)
|
||||
{
|
||||
_api.ActivateModelAsync(new ActivateModelIn(){Name = modelName}).Wait();
|
||||
lock (_lock)
|
||||
{
|
||||
_api.ActivateModelAsync(new ActivateModelIn() { Name = modelName }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public int[] GetAcceptSize()
|
||||
{
|
||||
var response = _api.GetAcceptSizeAsync().Result;
|
||||
|
||||
return response.Accept_size.ToArray();
|
||||
}
|
||||
|
||||
public int[] GetOutputSize()
|
||||
{
|
||||
var response = _api.GetOutputSizeAsync().Result;
|
||||
|
||||
return response.Accept_size.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public byte[] PredictRaw(byte[] byteArray)
|
||||
{
|
||||
var response = _api.PredictRawAsync(new FileParameter(new MemoryStream(byteArray))).Result;
|
||||
var stream = response.Stream;
|
||||
// read the stream to byte array
|
||||
using var memoryStream = new MemoryStream();
|
||||
stream.CopyTo(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -92,16 +90,15 @@ public class CSharpDataTransferHTTP
|
||||
|
||||
public byte[] Predict(byte[] byteArray)
|
||||
{
|
||||
var response = _api.PredictAsync(new FileParameter(new MemoryStream(byteArray))).Result;
|
||||
var stream = response.Stream;
|
||||
// read the stream to byte array
|
||||
using var memoryStream = new MemoryStream();
|
||||
stream.CopyTo(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
var responseBytes = memoryStream.ToArray();
|
||||
return responseBytes;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
var response = _api.PredictAsync(new FileParameter(new MemoryStream(byteArray))).Result;
|
||||
var stream = response.Stream;
|
||||
using var memoryStream = new MemoryStream();
|
||||
stream.CopyTo(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
var responseBytes = memoryStream.ToArray();
|
||||
return responseBytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user