Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,41 +3,56 @@ import tensorflow as tf
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
|
6 |
-
|
7 |
model = tf.saved_model.load('saved_model/embryo_classifier')
|
8 |
|
9 |
-
|
10 |
IMG_SIZE = (300, 300)
|
11 |
|
12 |
-
|
13 |
def preprocess_image(image):
|
14 |
-
image = image.resize(IMG_SIZE, Image.LANCZOS)
|
15 |
inp_numpy = np.array(image)[None]
|
16 |
inp = tf.constant(inp_numpy, dtype='float32')
|
17 |
return inp
|
18 |
|
19 |
-
|
|
|
|
|
20 |
st.title("Embryo Quality Assessment")
|
|
|
|
|
|
|
21 |
|
22 |
-
st.write("Upload an embryo image to classify its quality.")
|
23 |
|
24 |
-
# File uploader
|
25 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
26 |
|
27 |
if uploaded_file is not None:
|
28 |
image = Image.open(uploaded_file).convert('RGB')
|
29 |
-
|
|
|
30 |
|
31 |
st.write("Classifying...")
|
32 |
|
33 |
-
|
34 |
processed_image = preprocess_image(image)
|
35 |
|
36 |
-
|
37 |
class_scores = model(processed_image)[0].numpy()
|
38 |
predicted_class = class_scores.argmax()
|
39 |
|
40 |
-
|
41 |
classes = ['Low Quality', 'Medium Quality', 'High Quality'] # Adjust according to your classes
|
42 |
-
st.write(f"Prediction
|
43 |
-
st.write(f"Confidence
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
|
6 |
+
|
7 |
model = tf.saved_model.load('saved_model/embryo_classifier')
|
8 |
|
9 |
+
|
10 |
IMG_SIZE = (300, 300)
|
11 |
|
12 |
+
|
13 |
def preprocess_image(image):
|
14 |
+
image = image.resize(IMG_SIZE, Image.LANCZOS)
|
15 |
inp_numpy = np.array(image)[None]
|
16 |
inp = tf.constant(inp_numpy, dtype='float32')
|
17 |
return inp
|
18 |
|
19 |
+
|
20 |
+
st.set_page_config(page_title="Embryo Quality Assessment", layout="wide")
|
21 |
+
|
22 |
st.title("Embryo Quality Assessment")
|
23 |
+
st.write("""
|
24 |
+
Upload an embryo image to classify its quality. The model will predict the quality of the embryo as either Low, Medium, or High.
|
25 |
+
""")
|
26 |
|
|
|
27 |
|
|
|
28 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
29 |
|
30 |
if uploaded_file is not None:
|
31 |
image = Image.open(uploaded_file).convert('RGB')
|
32 |
+
resized_image = image.resize((150, 150))
|
33 |
+
st.image(resized_image, caption='Uploaded Image.', use_column_width=False)
|
34 |
|
35 |
st.write("Classifying...")
|
36 |
|
37 |
+
|
38 |
processed_image = preprocess_image(image)
|
39 |
|
40 |
+
|
41 |
class_scores = model(processed_image)[0].numpy()
|
42 |
predicted_class = class_scores.argmax()
|
43 |
|
44 |
+
|
45 |
classes = ['Low Quality', 'Medium Quality', 'High Quality'] # Adjust according to your classes
|
46 |
+
st.write(f"**Prediction:** {classes[predicted_class]}")
|
47 |
+
st.write(f"**Confidence:** {np.max(class_scores) * 100:.2f}%")
|
48 |
+
|
49 |
+
|
50 |
+
st.write("**Confidence scores for all classes:**")
|
51 |
+
for i, score in enumerate(class_scores):
|
52 |
+
st.write(f"{classes[i]}: {score * 100:.2f}%")
|
53 |
+
|
54 |
+
|
55 |
+
st.markdown("""
|
56 |
+
---
|
57 |
+
*Created by [Your Name](https://your-link.com)*
|
58 |
+
""")
|