Allow pull data from python all the way through to the UI

This commit is contained in:
2026-02-17 21:14:20 -08:00
parent 8d599be940
commit 26c995877e
3 changed files with 20 additions and 7 deletions
+4 -2
View File
@@ -1,4 +1,6 @@
import os
import json
import numpy as np
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
import yfinance as yf
import features
@@ -33,8 +35,8 @@ def Predict():
predictions = reconstructed_model.predict(df)
# 'predictions' will be a 2D array, flatten it if you want a simple list
flat_predictions = predictions.flatten()
flat_predictions = predictions.flatten().tolist()
print(f"Predicted Target_Close_Tomorrow: {flat_predictions}")
return flat_predictions
return json.dumps(flat_predictions)
+10 -3
View File
@@ -21,6 +21,11 @@
<div class="main-area">
<button @onclick="pullandtrain">@button1Text</button>
<button @onclick="predict">@button2Text</button>
@foreach(double cur in predictions){
<p>@cur</p><br/>
}
</div>
@@ -29,6 +34,8 @@
string button1Text = "Train AI";
string button2Text = "Predict AI";
double[] predictions = {};
async Task pullandtrain(){
button1Text = "Do not refresh the page. The data is refreshing.";
await Task.Delay(1);
@@ -37,10 +44,10 @@
}
async Task predict(){
button1Text = "Do not refresh the page. The data is refreshing.";
button2Text = "Do not refresh the page. The data is refreshing.";
await Task.Delay(1);
aiModule.TrainAI();
button1Text = "Refresh Completed";
predictions = aiModule.PredictAI();
button2Text = "Refresh Completed";
}
}
+6 -2
View File
@@ -1,4 +1,5 @@
using Python.Runtime;
using System.Text.Json;
namespace PythonInterop {
@@ -29,10 +30,13 @@ namespace PythonInterop {
}
}
public void PredictAI() {
public double[] PredictAI() {
using (Py.GIL()) {
dynamic main = Py.Import("ai-predictor");
dynamic result = main.Predict();
string result = main.Predict();
double[]? predictions = JsonSerializer.Deserialize<double[]>(result);
double[] nullCasted = predictions != null ? predictions : [];
return nullCasted;
}
}