tykimos commited on
Commit
ac719d0
·
1 Parent(s): c2116fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -3
app.py CHANGED
@@ -1,7 +1,51 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
 
3
+ label_dict = {}
 
4
 
5
+ f = open('baseline_keras_model_labels.txt', 'r')
6
+
7
+ lines = f.readlines()
8
+ for line in lines:
9
+ index, label_name = line.split(' ')
10
+ label_dict[int(index)] = label_name.strip()
11
+ f.close()
12
+
13
+ from keras.models import load_model
14
+ from PIL import Image, ImageOps
15
+ import numpy as np
16
+ import os
17
+
18
+ # Load the model
19
+ model = load_model('baseline_keras_model.h5')
20
+
21
+ # Create the array of the right shape to feed into the keras model
22
+ # The 'length' or number of images you can put into the array is
23
+ # determined by the first position in the shape tuple, in this case 1.
24
+ data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
25
+ # Replace this with the path to your image
26
+
27
+ folder_path = 'x_test'
28
+
29
+ y_pred = []
30
+
31
+ def clf(name):
32
+
33
+ image = Image.open(fpath)
34
+ size = (224, 224)
35
+ image = ImageOps.fit(image, size, Image.ANTIALIAS)
36
+
37
+ #turn the image into a numpy array
38
+ image_array = np.asarray(image)
39
+ # Normalize the image
40
+ normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
41
+ # Load the image into the array
42
+ data[0] = normalized_image_array
43
+
44
+ # run the inference
45
+ prediction = model.predict(data)
46
+ class_index = np.argmax(prediction)
47
+
48
+ return label_dict[class_index]
49
+
50
+ iface = gr.Interface(fn=clf, inputs="image", outputs="text")
51
  iface.launch()