Allow pull data from python all the way through to the UI
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
import numpy as np
|
||||||
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
||||||
import yfinance as yf
|
import yfinance as yf
|
||||||
import features
|
import features
|
||||||
@@ -33,8 +35,8 @@ def Predict():
|
|||||||
predictions = reconstructed_model.predict(df)
|
predictions = reconstructed_model.predict(df)
|
||||||
|
|
||||||
# 'predictions' will be a 2D array, flatten it if you want a simple list
|
# '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}")
|
print(f"Predicted Target_Close_Tomorrow: {flat_predictions}")
|
||||||
|
|
||||||
return flat_predictions
|
return json.dumps(flat_predictions)
|
||||||
@@ -21,6 +21,11 @@
|
|||||||
<div class="main-area">
|
<div class="main-area">
|
||||||
<button @onclick="pullandtrain">@button1Text</button>
|
<button @onclick="pullandtrain">@button1Text</button>
|
||||||
<button @onclick="predict">@button2Text</button>
|
<button @onclick="predict">@button2Text</button>
|
||||||
|
|
||||||
|
@foreach(double cur in predictions){
|
||||||
|
<p>@cur</p><br/>
|
||||||
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +34,8 @@
|
|||||||
string button1Text = "Train AI";
|
string button1Text = "Train AI";
|
||||||
string button2Text = "Predict AI";
|
string button2Text = "Predict AI";
|
||||||
|
|
||||||
|
double[] predictions = {};
|
||||||
|
|
||||||
async Task pullandtrain(){
|
async Task pullandtrain(){
|
||||||
button1Text = "Do not refresh the page. The data is refreshing.";
|
button1Text = "Do not refresh the page. The data is refreshing.";
|
||||||
await Task.Delay(1);
|
await Task.Delay(1);
|
||||||
@@ -37,10 +44,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async Task predict(){
|
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);
|
await Task.Delay(1);
|
||||||
aiModule.TrainAI();
|
predictions = aiModule.PredictAI();
|
||||||
button1Text = "Refresh Completed";
|
button2Text = "Refresh Completed";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Python.Runtime;
|
using Python.Runtime;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace PythonInterop {
|
namespace PythonInterop {
|
||||||
|
|
||||||
@@ -29,10 +30,13 @@ namespace PythonInterop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PredictAI() {
|
public double[] PredictAI() {
|
||||||
using (Py.GIL()) {
|
using (Py.GIL()) {
|
||||||
dynamic main = Py.Import("ai-predictor");
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user