File size: 1,716 Bytes
db7295e
446d568
db7295e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446d568
db7295e
 
 
446d568
db7295e
 
446d568
db7295e
446d568
db7295e
446d568
db7295e
 
446d568
db7295e
 
 
446d568
db7295e
 
 
446d568
db7295e
 
 
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
import streamlit as st
import torch
import torch.nn as nn

# Define your model architecture here (same as before)
class RegressionModel2(nn.Module):
    def __init__(self, input_dim2, hidden_dim2, output_dim2):
        super(RegressionModel2, self).__init__()
        self.fc1 = nn.Linear(input_dim2, hidden_dim2)
        self.relu1 = nn.ReLU()  # ReLU activation function
        self.fc2 = nn.Linear(hidden_dim2, output_dim2)
        self.batch_norm1 = nn.BatchNorm1d(hidden_dim2)  # Batch normalization

    def forward(self, x2):
        out = self.fc1(x2)
        out = self.relu1(out)
        out = self.batch_norm1(out)
        out = self.fc2(out)
        return out

# Load your saved model state dictionary (assuming 'model.pt' is uploaded)
model2 = RegressionModel2(input_dim2, hidden_dim2, output_dim2)
model2.load_state_dict(torch.load('model.pt'))
model2.eval()  # Set the model to evaluation mode

def predict(age, aca, axis):
  """
  This function takes three arguments (age, axis, aca) as input,
  prepares the data, makes a prediction using the loaded model,
  and returns the predicted value.
  """
  # Prepare the input data
  data = torch.tensor([[age, aca, axis]], dtype=torch.float32)

  # Make prediction
  with torch.no_grad():
    prediction = model2(data)

  # Return the predicted value
  return prediction.item()

# Streamlit App
st.title("Astigmatism Prediction App")
st.write("Enter the patient's information:")

age = st.number_input("Age", min_value=0)
aca = st.number_input("ACA Magnitude", min_value=0)
axis = st.number_input("ACA Axis", min_value=0)

if st.button("Predict"):
  predicted_value = predict(age, aca, axis)
  st.write(f"Predicted Astigmatism Value: {predicted_value}")