yuragoithf
commited on
Commit
·
7c5859b
1
Parent(s):
7f17609
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ model_file = download_model()
|
|
31 |
# Load the model
|
32 |
model = tf.keras.models.load_model(model_file)
|
33 |
|
34 |
-
# Perform image classification
|
35 |
# def predict_class(image):
|
36 |
# img = tf.cast(image, tf.float32)
|
37 |
# img = tf.image.resize(img, [input_shape[0], input_shape[1]])
|
@@ -41,6 +41,7 @@ model = tf.keras.models.load_model(model_file)
|
|
41 |
# predicted_class = labels[class_index]
|
42 |
# return predicted_class
|
43 |
|
|
|
44 |
def predict_class(image):
|
45 |
img = tf.cast(image, tf.float32)
|
46 |
img = tf.image.resize(img, [input_shape[0], input_shape[1]])
|
@@ -48,26 +49,22 @@ def predict_class(image):
|
|
48 |
prediction = model.predict(img)
|
49 |
return prediction[0]
|
50 |
|
51 |
-
# UI Design
|
52 |
# def classify_image(image):
|
53 |
# predicted_class = predict_class(image)
|
54 |
# output = f"<h2>Predicted Class: <span style='text-transform:uppercase';>{predicted_class}</span></h2>"
|
55 |
# return output
|
56 |
|
|
|
|
|
57 |
def classify_image(image):
|
58 |
results = predict_class(image)
|
59 |
-
# output = {}
|
60 |
-
# for index in range(len(results)):
|
61 |
-
# predicted_label = labels.get(index)
|
62 |
-
# score = results[index]
|
63 |
-
# output[predicted_label] = str(score)
|
64 |
output = {labels.get(i): float(results[i]) for i in range(len(results))}
|
65 |
return output
|
66 |
|
67 |
|
68 |
-
|
69 |
inputs = gr.inputs.Image(type="pil", label="Upload an image")
|
70 |
-
# outputs = gr.outputs.HTML()
|
71 |
outputs = gr.outputs.Label(num_top_classes=5)
|
72 |
|
73 |
title = "<h1 style='text-align: center;'>Image Classifier</h1>"
|
|
|
31 |
# Load the model
|
32 |
model = tf.keras.models.load_model(model_file)
|
33 |
|
34 |
+
# Perform image classification for single class output
|
35 |
# def predict_class(image):
|
36 |
# img = tf.cast(image, tf.float32)
|
37 |
# img = tf.image.resize(img, [input_shape[0], input_shape[1]])
|
|
|
41 |
# predicted_class = labels[class_index]
|
42 |
# return predicted_class
|
43 |
|
44 |
+
# Perform image classification for multy class output
|
45 |
def predict_class(image):
|
46 |
img = tf.cast(image, tf.float32)
|
47 |
img = tf.image.resize(img, [input_shape[0], input_shape[1]])
|
|
|
49 |
prediction = model.predict(img)
|
50 |
return prediction[0]
|
51 |
|
52 |
+
# UI Design for single class output
|
53 |
# def classify_image(image):
|
54 |
# predicted_class = predict_class(image)
|
55 |
# output = f"<h2>Predicted Class: <span style='text-transform:uppercase';>{predicted_class}</span></h2>"
|
56 |
# return output
|
57 |
|
58 |
+
|
59 |
+
# UI Design for multy class output
|
60 |
def classify_image(image):
|
61 |
results = predict_class(image)
|
|
|
|
|
|
|
|
|
|
|
62 |
output = {labels.get(i): float(results[i]) for i in range(len(results))}
|
63 |
return output
|
64 |
|
65 |
|
|
|
66 |
inputs = gr.inputs.Image(type="pil", label="Upload an image")
|
67 |
+
# outputs = gr.outputs.HTML() #uncomment for single class output
|
68 |
outputs = gr.outputs.Label(num_top_classes=5)
|
69 |
|
70 |
title = "<h1 style='text-align: center;'>Image Classifier</h1>"
|