Upload 7 files
Browse files- ampollaaa.jpg +0 -0
- app.py +37 -0
- cartrooo1.jpg +0 -0
- keras_model.h5 +3 -0
- labels.txt +5 -0
- requirements.txt +5 -0
- vidreeeee.jpg +0 -0
ampollaaa.jpg
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 22 |
+
return class_name[2:], confidence_score
|
| 23 |
+
|
| 24 |
+
in_img = gr.Image(type="pil")
|
| 25 |
+
etiqueta = gr.Textbox(label='Aix貌 茅s...')
|
| 26 |
+
percentatge = gr.Textbox(label='robabilitat:')
|
| 27 |
+
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=pred,
|
| 30 |
+
inputs=in_img,
|
| 31 |
+
outputs=[etiqueta, percentatge],
|
| 32 |
+
allow_flagging="never",
|
| 33 |
+
css='footer {visibility: hidden}',
|
| 34 |
+
theme=gr.themes.Monochrome(),
|
| 35 |
+
examples=['/content/ampollaaa.jpg','/content/vidreeeee.jpg','/content/cartrooo1.jpg'])
|
| 36 |
+
|
| 37 |
+
demo.launch(debug=True)
|
cartrooo1.jpg
ADDED
|
keras_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:46400f3ec395f14170acb8c160f2ace1124dfaaa40626d246e0443a93462e730
|
| 3 |
+
size 2456608
|
labels.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0 Vidre
|
| 2 |
+
1 Paper
|
| 3 |
+
2 Cartr贸
|
| 4 |
+
3 Metall
|
| 5 |
+
4 Pl脿stic
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
gradio
|
| 3 |
+
pillow
|
| 4 |
+
keras
|
| 5 |
+
tensorflow == 2.12
|
vidreeeee.jpg
ADDED
|