yuragoithf commited on
Commit
130f1d3
·
verified ·
1 Parent(s): 64d390c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -30,7 +30,7 @@ def download_model():
30
  model_file = download_model()
31
 
32
  # Load the model
33
- model = tf.keras.models.load_model(model_file, compile=True)
34
 
35
  # Perform image classification for single class output
36
  # def predict_class(image):
@@ -51,25 +51,25 @@ def predict_class(image):
51
  return prediction[0]
52
 
53
  # UI Design for single class output
54
- def classify_image(image):
55
- predicted_class = predict_class(image)
56
- output = f"<h2>Predicted Class: <span style='text-transform:uppercase';>{predicted_class}</span></h2>"
57
- return output
58
 
59
 
60
  # UI Design for multy class output
61
- # def classify_image(image):
62
- # results = predict_class(image)
63
- # print("results is ...", results)
64
- # output = {labels.get(i): float(results[i]) for i in range(len(results))}
65
- # print("output is ...", output)
66
- # result = output if max(output.values()) >=0.98 else {"NO_CIFAR10_CLASS": 1}
67
- # return result
68
 
69
 
70
  inputs = gr.components.Image(type="pil", label="Upload an image")
71
- outputs = gr.outputs.HTML() #uncomment for single class output
72
- # outputs = gr.components.Label(num_top_classes=4)
73
 
74
  title = "<h1 style='text-align: center;'>Image Classifier</h1>"
75
  description = "Upload an image and get the predicted class."
 
30
  model_file = download_model()
31
 
32
  # Load the model
33
+ model = tf.keras.models.load_model(model_file)
34
 
35
  # Perform image classification for single class output
36
  # def predict_class(image):
 
51
  return prediction[0]
52
 
53
  # UI Design for single class output
54
+ # def classify_image(image):
55
+ # predicted_class = predict_class(image)
56
+ # output = f"<h2>Predicted Class: <span style='text-transform:uppercase';>{predicted_class}</span></h2>"
57
+ # return output
58
 
59
 
60
  # UI Design for multy class output
61
+ def classify_image(image):
62
+ results = predict_class(image)
63
+ print("results is ...", results)
64
+ output = {labels.get(i): float(results[i]) for i in range(len(results))}
65
+ print("output is ...", output)
66
+ result = output if max(output.values()) >=0.98 else {"NO_CIFAR10_CLASS": 1}
67
+ return result
68
 
69
 
70
  inputs = gr.components.Image(type="pil", label="Upload an image")
71
+ # outputs = gr.outputs.HTML() #uncomment for single class output
72
+ outputs = gr.components.Label(num_top_classes=4)
73
 
74
  title = "<h1 style='text-align: center;'>Image Classifier</h1>"
75
  description = "Upload an image and get the predicted class."