Spaces:
Runtime error
Runtime error
Commit
·
b17cf68
1
Parent(s):
a27336c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from keras.preprocessing import image
|
4 |
+
from keras.applications.vgg16 import preprocess_input, decode_predictions
|
5 |
+
import numpy as np
|
6 |
+
import numpy as np
|
7 |
+
import pandas as pd
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
from glob import glob
|
10 |
+
# loading the directories
|
11 |
+
# importing the libraries
|
12 |
+
import tensorflow as tf
|
13 |
+
from tensorflow.keras.models import Model
|
14 |
+
from tensorflow.keras.layers import Flatten, Dense
|
15 |
+
from tensorflow.keras.applications import VGG16
|
16 |
+
#from keras.preprocessing import image
|
17 |
+
num_classes=10
|
18 |
+
IMAGE_SHAPE = [224, 224]
|
19 |
+
|
20 |
+
class_labels = ['exterior_building','icons','interior_building','landscapes','layouts','others','people','scanned_documents','signatures','under_construction']
|
21 |
+
|
22 |
+
|
23 |
+
def greet(name):
|
24 |
+
return "Hello " + name + "!!"
|
25 |
+
|
26 |
+
|
27 |
+
model = tf.keras.models.load_model("./classification_model.h5")
|
28 |
+
class_labels = ['exterior_building','icons','interior_building','landscapes','layouts','others','people','scanned_documents','signatures','under_construction']
|
29 |
+
|
30 |
+
def predict_image(image):
|
31 |
+
|
32 |
+
|
33 |
+
# img_path = '/Users/balamuruga/Desktop/Screenshot 2023-11-08 at 9.22.52 PM.png'
|
34 |
+
# img = image.load_img(img_path, target_size=(224, 224))
|
35 |
+
# x = image.img_to_array(img)
|
36 |
+
# x = np.expand_dims(x, axis=0)
|
37 |
+
# x = preprocess_input(x)
|
38 |
+
image = image.reshape((-1, 224, 224, 3))
|
39 |
+
|
40 |
+
|
41 |
+
# preds=model.predict(image)
|
42 |
+
prediction = model.predict(image).flatten()
|
43 |
+
print(prediction)
|
44 |
+
return {class_labels[i]: float(prediction[i]) for i in range(10)}
|
45 |
+
|
46 |
+
# create a list containing the class labels
|
47 |
+
|
48 |
+
# # find the index of the class with maximum score
|
49 |
+
# pred = np.argmax(preds, axis=-1)
|
50 |
+
|
51 |
+
# # print the label of the class with maximum score
|
52 |
+
# print(class_labels[pred[0]])
|
53 |
+
# return {class_labels[i]: float(pred[i]) for i in range(10)}
|
54 |
+
|
55 |
+
# img_4d=img.reshape(-1,256,256,3)
|
56 |
+
# prediction=model.predict(img_4d)[0]
|
57 |
+
# return {class_names[i]: float(prediction[i]) for i in range(5)}
|
58 |
+
|
59 |
+
# iface = gr.Interface(fn=predict_image, inputs="text", outputs="text")
|
60 |
+
# iface.launch()
|
61 |
+
|
62 |
+
|
63 |
+
image = gr.inputs.Image(shape = (224, 224))
|
64 |
+
label = gr.outputs.Label(num_top_classes = 10)
|
65 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch(debug='True')
|