sensei-ml commited on
Commit
d60e533
·
1 Parent(s): a924053

Add first model of the interface and incorporate the CNN model

Browse files
Files changed (3) hide show
  1. app.py +10 -5
  2. model/model.h5 +3 -0
  3. model/model.py +15 -0
app.py CHANGED
@@ -1,12 +1,17 @@
 
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
5
 
6
  demo = gr.Interface(
7
- #fn=classify_image,
8
- inputs=gr.Image(),
9
- outputs=gr.Label(num_top_classes=4),
10
  title="Image Classifier",
11
  description="Upload an image and get the top 4 predicted labels with probabilities.",)
12
  demo.launch()
 
1
+ from model import model
2
  import gradio as gr
3
+ import numpy as np
4
 
5
+ def classify_image(image):
6
+ probabilities = model.predict(image.name) # Call prediction function
7
+ labels = ["Category1", "Category2", "Category3", "Category4"] # Assing labels
8
+ top_labels = [labels[i] for i in np.argsort(probabilities)[::-1][:4]]
9
+ top_probs = [round(float(probabilities[i]), 4) for i in np.argsort(probabilities)[::-1][:4]]
10
 
11
  demo = gr.Interface(
12
+ fn=classify_image,
13
+ inputs=gr.inputs.Image(),
14
+ outputs=gr.outputs.Label(num_top_classes=4),
15
  title="Image Classifier",
16
  description="Upload an image and get the top 4 predicted labels with probabilities.",)
17
  demo.launch()
model/model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26c4d449632ea072317c16e9d4857e419b67e1b7751f81a89a87c8e75fe9484e
3
+ size 800
model/model.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from keras.models import load_model
2
+ from PIL import Image
3
+ import keras
4
+ import numpy as np
5
+
6
+ model = load_model('model\model.h5')
7
+
8
+ def predict(image_path):
9
+ img = Image.open(image_path)
10
+ img = img.resize((255, 255)) # Resize to match your model's input size
11
+ img_array = np.array(img) / 255.0 # Normalize pixel values
12
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
13
+ predictions = model.predict(img_array)
14
+ return predictions[0] # Assuming a single output (adjust if needed)
15
+