File size: 2,781 Bytes
eefcc06 61c910c 701c8cb 61c910c eefcc06 dec535e 61c910c eefcc06 61c910c eefcc06 61c910c eefcc06 ed6950c a2d6b1e ed6950c e076636 eefcc06 7bf4a3a eefcc06 7bf4a3a eefcc06 9d9cda7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import gradio as gr
import pandas as pd
from sklearn.model_selection import train_test_split
import torch
import torch.nn as nn
class LaserPredictions(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
super(LaserPredictions, self).__init__()
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.relu1 = nn.ReLU()
self.fc2 = nn.Linear(hidden_dim, output_dim)
self.batch_norm1 = nn.BatchNorm1d(hidden_dim)
def forward(self, x2):
out = self.fc1(x2)
out = self.relu1(out)
out = self.batch_norm1(out)
out = self.fc2(out)
return out
# Load the saved model state dictionary
model = LaserPredictions(6, 32, 3)
model.load_state_dict(torch.load('laser_prescription_model.pt'))
model.eval() # Set the model to evaluation mode
import gradio as gr
import pandas as pd
from sklearn.model_selection import train_test_split
import torch
import torch.nn as nn
class LaserPredictions(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
super(LaserPredictions, self).__init__()
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.relu1 = nn.ReLU()
self.fc2 = nn.Linear(hidden_dim, output_dim)
self.batch_norm1 = nn.BatchNorm1d(hidden_dim)
def forward(self, x2):
out = self.fc1(x2)
out = self.relu1(out)
out = self.batch_norm1(out)
out = self.fc2(out)
return out
# Load the saved model state dictionary
model = LaserPredictions(6, 32, 3)
model.load_state_dict(torch.load('laser_prescription_model.pt'))
model.eval() # Set the model to evaluation mode
def predict(pre_op_sphere, pre_op_cylinder, pre_op_axis):
# Use zero values for post-op features, as the target prescription is set to 0
post_op_values = [0.0, 0.0, 0.0]
# Combine pre-op and post-op values
input_data = [pre_op_sphere, pre_op_cylinder, pre_op_axis] + post_op_values
input_tensor = torch.tensor([input_data], dtype=torch.float32)
with torch.no_grad():
predicted_prescription = model(input_tensor)
predicted_sphere = predicted_prescription[0][0].item()
predicted_cylinder = predicted_prescription[0][1].item()
predicted_axis = predicted_prescription[0][2].item()
return f"Predicted Laser Prescription:\nSphere: {predicted_sphere:.2f}\nCylinder: {predicted_cylinder:.2f}\nAxis: {predicted_axis:.2f}"
css = """
.gradio-container {
background-color: #131517;
}
"""
inputs = [
gr.Number(label="Pre-Op Sphere"),
gr.Number(label="Pre-Op Cylinder"),
gr.Number(label="Pre-Op Axis"),
]
output = gr.Textbox(label="Predicted Laser Prescription")
gr.Interface(fn=predict, inputs=inputs, outputs=output, title="Laser Treatment Prediction", css=css).launch(share=True) |