Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| interpreter = tf.lite.Interpreter(model_path="leaf_model_85_percent.tflite") | |
| interpreter.allocate_tensors() | |
| input_details = interpreter.get_input_details() | |
| output_details = interpreter.get_output_details() | |
| def classify(image): | |
| img = image.resize((224, 224)).convert("RGB") | |
| img_array = np.array(img) / 255.0 | |
| img_array = np.expand_dims(img_array, axis=0).astype(np.float32) | |
| interpreter.set_tensor(input_details[0]['index'], img_array) | |
| interpreter.invoke() | |
| output = interpreter.get_tensor(output_details[0]['index'])[0][0] | |
| return "Unhealthy" if output > 0.45 else "Healthy" | |
| iface = gr.Interface(fn=classify, inputs=gr.Image(type="pil"), outputs="text") | |
| iface.launch(debug=True, share=True) | |