File size: 1,678 Bytes
eefcc06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dec535e
eefcc06
 
 
dec535e
 
eefcc06
 
 
 
 
 
 
 
 
 
 
7bf4a3a
 
 
eefcc06
7bf4a3a
eefcc06
 
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
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(3, 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):
    input_data = torch.tensor([[pre_op_sphere, pre_op_cylinder, pre_op_axis]], dtype=torch.float32)
    
    with torch.no_grad():
        predicted_prescription = model(input_data)
    
    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}"

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 Prescription Prediction").launch()