Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +40 -0
- dental_model.h5 +3 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from tensorflow import keras
|
5 |
+
import tensorflow as tf
|
6 |
+
from keras.models import load_model
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
from PIL import Image
|
9 |
+
|
10 |
+
st.title('Dental Type Segmentation')
|
11 |
+
|
12 |
+
# Load the saved model outside the prediction function
|
13 |
+
loaded_model = load_model('dental_model.h5')
|
14 |
+
|
15 |
+
def prediction(file):
|
16 |
+
img = tf.keras.utils.load_img(file, target_size=(224, 224))
|
17 |
+
x = tf.keras.utils.img_to_array(img)
|
18 |
+
x = np.expand_dims(x, axis=0)
|
19 |
+
|
20 |
+
# Predict the class probabilities
|
21 |
+
classes = loaded_model.predict(x)
|
22 |
+
|
23 |
+
# Get the predicted class label
|
24 |
+
classes = np.ravel(classes) # convert to 1D array
|
25 |
+
idx = np.argmax(classes)
|
26 |
+
clas = ['Segmentation1', 'Segmentation2'][idx]
|
27 |
+
|
28 |
+
return clas
|
29 |
+
|
30 |
+
uploaded_file = st.file_uploader("Choose X-ray file")
|
31 |
+
if uploaded_file is not None:
|
32 |
+
image = Image.open(uploaded_file)
|
33 |
+
image = image.resize((224, 224))
|
34 |
+
image = tf.keras.preprocessing.image.img_to_array(image)
|
35 |
+
image = image / 255.0
|
36 |
+
image = tf.expand_dims(image, axis=0)
|
37 |
+
|
38 |
+
if st.button('Predict'):
|
39 |
+
result = prediction(uploaded_file)
|
40 |
+
st.write('Prediction is {}'.format(result))
|
dental_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:481f2e7105c2543e787aff73624b50a9dc8fd31abaf08c8da8b834312c7a678c
|
3 |
+
size 31251320
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
scikit-learn==1.2.2
|
4 |
+
tensorflow==2.12.0
|
5 |
+
keras
|
6 |
+
matplotlib
|