| import gradio as gr |
| from keras.models import load_model |
| from PIL import Image, ImageOps |
| import numpy as np |
|
|
| |
| model = load_model("keras_model.h5", compile=False) |
|
|
| |
| class_names = open("labels.txt", "r").readlines() |
|
|
| def image_classifier(image): |
|
|
| |
| np.set_printoptions(suppress=True) |
|
|
| |
| |
| |
| data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32) |
|
|
| |
| |
| image = Image.fromarray(image.astype("uint8"),"RGB") |
|
|
| |
| size = (224, 224) |
| image = ImageOps.fit(image, size, Image.Resampling.LANCZOS) |
|
|
| |
| image_array = np.asarray(image) |
|
|
| |
| normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1 |
|
|
| |
| data[0] = normalized_image_array |
|
|
| |
| prediction = model.predict(data) |
| index = np.argmax(prediction) |
| class_name = class_names[index] |
| confidence_score = prediction[0][index] |
|
|
| |
| result = class_name[2:] |
| if index == 2: |
| text1 ='δΊθ§γ§γ' |
| elif index == 0: |
| text1 ='θ¦ζγ§γ' |
| elif index == 1: |
| text1 ='ζε©γ§γ' |
| ans = result + text1 |
| return ans |
|
|
| demo = gr.Interface( |
| fn=image_classifier, |
| inputs=gr.Image(), |
| outputs="text" |
| ) |
|
|
| demo.launch(debug=True, share=True) |