Balamuruga's picture
Create app.py
b17cf68
import gradio as gr
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input, decode_predictions
import numpy as np
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from glob import glob
# loading the directories
# importing the libraries
import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Flatten, Dense
from tensorflow.keras.applications import VGG16
#from keras.preprocessing import image
num_classes=10
IMAGE_SHAPE = [224, 224]
class_labels = ['exterior_building','icons','interior_building','landscapes','layouts','others','people','scanned_documents','signatures','under_construction']
def greet(name):
return "Hello " + name + "!!"
model = tf.keras.models.load_model("./classification_model.h5")
class_labels = ['exterior_building','icons','interior_building','landscapes','layouts','others','people','scanned_documents','signatures','under_construction']
def predict_image(image):
# img_path = '/Users/balamuruga/Desktop/Screenshot 2023-11-08 at 9.22.52 PM.png'
# img = image.load_img(img_path, target_size=(224, 224))
# x = image.img_to_array(img)
# x = np.expand_dims(x, axis=0)
# x = preprocess_input(x)
image = image.reshape((-1, 224, 224, 3))
# preds=model.predict(image)
prediction = model.predict(image).flatten()
print(prediction)
return {class_labels[i]: float(prediction[i]) for i in range(10)}
# create a list containing the class labels
# # find the index of the class with maximum score
# pred = np.argmax(preds, axis=-1)
# # print the label of the class with maximum score
# print(class_labels[pred[0]])
# return {class_labels[i]: float(pred[i]) for i in range(10)}
# img_4d=img.reshape(-1,256,256,3)
# prediction=model.predict(img_4d)[0]
# return {class_names[i]: float(prediction[i]) for i in range(5)}
# iface = gr.Interface(fn=predict_image, inputs="text", outputs="text")
# iface.launch()
image = gr.inputs.Image(shape = (224, 224))
label = gr.outputs.Label(num_top_classes = 10)
gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch(debug='True')