Seperate out the PullAI on the front end

This commit is contained in:
2026-02-26 21:43:28 -08:00
parent 769c05d821
commit 9a0746fa8b
+13 -6
View File
@@ -1,5 +1,4 @@
using Python.Runtime; using Python.Runtime;
using System.Text.Json;
namespace PythonInterop { namespace PythonInterop {
@@ -22,21 +21,29 @@ namespace PythonInterop {
PythonEngine.BeginAllowThreads(); PythonEngine.BeginAllowThreads();
} }
// This is thread blocking, runs on the main thread, and takes multiple minutes so probabaly need to run on a background thread at some point public void PullAI() {
using (Py.GIL()) {
dynamic datapuller = Py.Import("datapuller");
using (datapuller.pull()){ }
}
}
public void TrainAI() { public void TrainAI() {
using (Py.GIL()) { using (Py.GIL()) {
dynamic datapuller = Py.Import("ai-trainer"); dynamic trainer = Py.Import("ai-trainer");
dynamic result = datapuller.TrainAI(); using (trainer.TrainAI()){ }
} }
} }
public int PredictAI(string StockSymbol) { public int PredictAI(string StockSymbol) {
using (Py.GIL()) { using (Py.GIL()) {
dynamic main = Py.Import("ai-predictor"); dynamic predictor = Py.Import("ai-predictor");
int result = main.Predict(StockSymbol); using (dynamic x = predictor.Predict(StockSymbol)) {
int result = (int)x;
return result; return result;
} }
} }
}
} }