szili2011 commited on
Commit
6ac8084
1 Parent(s): 771c324

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -24
app.py CHANGED
@@ -1,34 +1,23 @@
1
  import gradio as gr
2
- from keras.models import load_model
3
- import numpy as np
4
- from PIL import Image
5
 
6
  # Load your model
7
- model = load_model('pain_analysis.h5') # Use the correct filename
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)) # Resize if needed
13
- image = np.array(image) / 255.0 # Scale pixel values to [0, 1]
14
  image = np.expand_dims(image, axis=0) # Add batch dimension
 
 
15
 
16
- # Make prediction
17
- prediction = model.predict(image)
18
- predicted_class = np.argmax(prediction, axis=1) # Get the index of the highest score
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
- # Create Gradio interface
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 interface
34
- iface.launch()
 
 
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()