File size: 3,367 Bytes
eefcc06 61c910c 701c8cb 61c910c eefcc06 dec535e 61c910c eefcc06 61c910c eefcc06 61c910c eefcc06 ed6950c a2d6b1e 7560df9 f6a7710 5c3250e 5e04b41 7560df9 a3e2a65 7560df9 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
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;
}
button {
background: #102534;
border: 1px solid #0c538c;
outline: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
color: #fff;
}
button:hover {
cursor: pointer;
opacity: .7;
}
input {
background-color: #202428;
color: #fff;
border: 1px solid #2d353c;
border-radius: 5px;
padding: 10px 20px;
outline: none;
font-size: 16px;
}
::-webkit-input-placeholder {
color: #7a848f;
}
input:focus::placeholder {
color: transparent;
}
#component-0 {
background-color: #202428;
}
footer {
visibility: hidden;
}
"""
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) |