File size: 1,793 Bytes
0b38715
 
 
 
43fbc49
75d623a
107902e
43fbc49
a687202
756261a
da4cf5c
 
0b38715
 
43fbc49
 
 
 
0b38715
 
43fbc49
 
 
 
0b38715
aa1165c
78588ac
0b481a9
c337084
78588ac
aa1165c
43fbc49
 
6d9fefc
2fb0b4c
 
cbd42a4
5058858
78588ac
60e022a
aa1165c
36a3ee3
43fbc49
 
 
 
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
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
from PIL import Image
from keras import layers

# Load your trained Xception model
model = tf.keras.models.load_model("xception-head")

# Define the labels for your classification
class_labels = ['fresh', 'early decay', 'advanced decay','skeletonized']  # Replace with your actual class names

def classify_image(img):
    # Preprocess the image to fit the model input shape
    img = img.resize((299, 299))  # Xception takes 299x299 input size
    img = np.array(img) / 255.0   # Normalize the image
    img = np.expand_dims(img, axis=0)

    # Make prediction
    predictions = model.predict(img)
    predicted_class = np.argmax(predictions, axis=1)[0]
    confidence = np.max(predictions)
    return {class_labels[i]: float(predictions[0][i]) for i in range(len(class_labels))}, confidence

# Example images (local paths or URLs)
example_images = [
    'fresh.jp',
    'skeletonized.jpeg'  # Replace with actual local file paths or URLs
]

# Gradio interface
demo = gr.Interface(
    fn=classify_image,
    title="Human Decomposition Image Classification",
    description = "Predict the stage of decay (fresh, early decay, advanced decay, or skeletonized) of a head. This is a demo of one of our human decomposition image classification <a href=\"https://huggingface.co/icputrd/megyesi_decomposition_classification/blob/main/head/xception\">models</a>.",
    inputs=gr.Image(type="pil"),
    outputs=[gr.Label(num_top_classes=len(class_labels)), gr.Number()],
    examples=example_images,
    cache_examples=False,
    live=True,
    article = "Author: <a href=\"https://www.linkedin.com/in/anna-maria-nau/\">Anna-Maria Nau</a>"
)

if __name__ == "__main__":
    demo.launch()