jarif commited on
Commit
81cd7be
1 Parent(s): 9ceecec

Upload 7 files

Browse files
Files changed (7) hide show
  1. app.py +48 -0
  2. image_1.jpeg +0 -0
  3. image_2.jpg +0 -0
  4. image_4.jpeg +0 -0
  5. image_5.jpg +0 -0
  6. image_7.jpg +0 -0
  7. image_8.jpeg +0 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing import image as keras_image
5
+ from tensorflow.image import resize
6
+
7
+ # Load the trained model
8
+ model = load_model("trained_model_10.h5")
9
+
10
+ # CIFAR-10 labels
11
+ label_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
12
+
13
+ # Define the function to recognize images
14
+ def recognize_image(image):
15
+ # Preprocess the image to fit the model input requirements
16
+ img = keras_image.img_to_array(image)
17
+ img = resize(img, (32, 32))
18
+ img = np.expand_dims(img, axis=0)
19
+ img = img / 255.0 # Normalizing if the model expects normalized input
20
+
21
+ # Make predictions
22
+ pred = model.predict(img)
23
+ final_pred = np.argmax(pred, axis=1)
24
+
25
+ # Create a dictionary mapping labels to their respective probabilities
26
+ result = {label_names[i]: float(pred[0][i]) for i in range(len(label_names))}
27
+
28
+ return result
29
+
30
+ # Define the input and output interfaces
31
+ image_input = gr.Image()
32
+ label_output = gr.Label(num_top_classes=5)
33
+
34
+ # Example images
35
+ examples = [
36
+ 'image_1.jpeg',
37
+ 'image_2.jpg',
38
+ 'image_4.jpeg',
39
+ 'image_5.jpg',
40
+ 'image_7.jpg',
41
+ 'image_8.jpeg'
42
+ ]
43
+
44
+ # Create the Gradio interface
45
+ iface = gr.Interface(fn=recognize_image, inputs=image_input, outputs=label_output, examples=examples)
46
+
47
+ # Launch the interface
48
+ iface.launch(inline=False)
image_1.jpeg ADDED
image_2.jpg ADDED
image_4.jpeg ADDED
image_5.jpg ADDED
image_7.jpg ADDED
image_8.jpeg ADDED