| | import gradio as gr |
| | import tensorflow as tf |
| | import numpy as np |
| | from PIL import Image |
| | import json |
| |
|
| | |
| | model = tf.keras.models.load_model("model.h5") |
| |
|
| | |
| | with open("categories.json", "r") as json_file: |
| | categories_data = json.load(json_file) |
| |
|
| | categories = [entry["category"] for entry in categories_data] |
| |
|
| | |
| | def classify_image(image): |
| | try: |
| | |
| | image = Image.fromarray(image.astype('uint8')) |
| | image = image.resize((100, 100)) |
| | image = np.array(image) |
| |
|
| | |
| | prediction = model.predict(image[None, ...]) |
| |
|
| | |
| | class_idx = np.argmax(prediction) |
| | class_label = categories[class_idx] |
| |
|
| | return class_label |
| | except Exception as e: |
| | return str(e) |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=classify_image, |
| | inputs=gr.inputs.Image(), |
| | outputs="text" |
| | ) |
| |
|
| | |
| | iface.launch() |
| |
|