Medvira commited on
Commit
660360a
·
verified ·
1 Parent(s): 77a70b0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import onnxruntime as ort
4
+
5
+ # Initialize the ONNX session
6
+ session = ort.InferenceSession("/content/bone_age_model.onnx")
7
+
8
+ # Define the inference function
9
+ def inference(sample_name):
10
+ sample = torch.load(f"/content/samples/{sample_name}")
11
+ age = sample['boneage'].item()
12
+ outputs = session.run(None, {"input": sample['path'].numpy()})
13
+ predicted_age = (outputs[0]*41.172)+127.329
14
+ return {
15
+ 'Bone age': age,
16
+ 'Predicted Bone age': predicted_age[0][0]
17
+ }
18
+
19
+ # List of sample file names
20
+ sample_files = [f"sample_{i}.pth" for i in range(1, 11)]
21
+
22
+ # Create Gradio interface
23
+ dropdown = gr.inputs.Dropdown(choices=sample_files, label="Select a sample")
24
+
25
+ iface = gr.Interface(
26
+ fn=inference,
27
+ inputs=dropdown,
28
+ outputs=[gr.outputs.Textbox(label="Bone Age"), gr.outputs.Textbox(label="Predicted Bone Age")],
29
+ title="Bone Age Prediction",
30
+ description="Select a sample from the dropdown to see the bone age and predicted bone age."
31
+ )
32
+
33
+ # Launch the app
34
+ iface.launch()