rcodina commited on
Commit
2ff37c4
·
verified ·
1 Parent(s): 42ed40d

Upload 5 files

Browse files
Files changed (5) hide show
  1. 1024_2000.jpeg +0 -0
  2. app.py +36 -0
  3. keras_model.h5 +3 -0
  4. labels.txt +2 -0
  5. requirements.txt +5 -0
1024_2000.jpeg ADDED
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from keras.models import load_model # TensorFlow is required for Keras to work
3
+ from PIL import Image, ImageOps # Install pillow instead of PIL
4
+ import numpy as np
5
+
6
+ model = load_model("/content/keras_model.h5", compile=False)
7
+ class_names = open("/content/labels.txt", "r").readlines()
8
+
9
+ def pred(img):
10
+ data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
11
+ image = img
12
+ size = (224, 224)
13
+ image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)
14
+ image_array = np.asarray(image)
15
+ normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
16
+ data[0] = normalized_image_array
17
+ prediction = model.predict(data)
18
+ index = np.argmax(prediction)
19
+ class_name = class_names[index]
20
+ confidence_score = prediction[0][index]
21
+ return class_name[2:], confidence_score
22
+
23
+ imatge_entrada = gr.Image(type='pil')
24
+ etiqueta = gr.Textbox(label='Això és...')
25
+ percentatge = gr.Textbox(label='Probabilitat:')
26
+
27
+ demo = gr.Interface(
28
+ fn=pred,
29
+ inputs=imatge_entrada,
30
+ outputs=[etiqueta, percentatge],
31
+ allow_flagging="never",
32
+ css="footer {visibility: hidden}",
33
+ theme=gr.themes.Soft(),
34
+ examples=["1024_2000.jpeg"])
35
+
36
+ demo.launch(debug=True)
keras_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e62a1d8282fe5bf29d366211cae043b3b31982566f1670b64a4037b5513bad3
3
+ size 2453432
labels.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ 0 Class 1
2
+ 1 Class 2
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ gradio
3
+ pillow
4
+ keras
5
+ tensorflow == 2.12