Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
import numpy as np
|
4 |
-
from PIL import Image
|
5 |
|
6 |
# Load your model
|
7 |
-
model = load_model(
|
8 |
|
9 |
-
# Define a prediction function
|
10 |
def predict(image):
|
11 |
# Preprocess the image as required by your model
|
12 |
-
image = image.resize((150, 150)) #
|
13 |
-
image = np.array(image) / 255.0 #
|
14 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# Convert predicted class index to label (optional)
|
21 |
-
class_labels = ['no_pain', 'low_pain', 'medium_pain', 'high_pain']
|
22 |
-
return class_labels[predicted_class[0]]
|
23 |
|
24 |
-
|
25 |
-
iface = gr.Interface(
|
26 |
-
fn=predict,
|
27 |
-
inputs=gr.inputs.Image(type="pil"),
|
28 |
-
outputs="label",
|
29 |
-
title="Pain Analysis Model",
|
30 |
-
description="Upload an image to get predictions of pain levels from the model."
|
31 |
-
)
|
32 |
|
33 |
-
# Launch the
|
34 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import tensorflow as tf
|
|
|
|
|
3 |
|
4 |
# Load your model
|
5 |
+
model = tf.keras.models.load_model("pain_analysis.h5")
|
6 |
|
|
|
7 |
def predict(image):
|
8 |
# Preprocess the image as required by your model
|
9 |
+
image = image.resize((150, 150)) # Assuming your model expects 150x150 input
|
10 |
+
image = np.array(image) / 255.0 # Normalize the image
|
11 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
12 |
+
predictions = model.predict(image)
|
13 |
+
return predictions.tolist() # Adjust the output format as needed
|
14 |
|
15 |
+
# Define the Gradio interface
|
16 |
+
inputs = gr.Image(type="pil") # Updated input definition
|
17 |
+
outputs = gr.Label(num_top_classes=4) # Adjust according to your model's output
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
interface = gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title="Pain Analysis Model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Launch the app
|
22 |
+
if __name__ == "__main__":
|
23 |
+
interface.launch()
|