Anas090 commited on
Commit
45bc23d
·
verified ·
1 Parent(s): 97bbece

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -20
app.py CHANGED
@@ -1,15 +1,3 @@
1
- import gradio as gr
2
- import cv2
3
- import onnxruntime
4
- import numpy as np
5
-
6
- onnx_model_vgg19_path = "./vgg19-30epochs.onnx"
7
- onnx_model_inceptionv3_path = "./InceptionV3-20epochs.onnx"
8
- onnx_model_resnet101_path = "./Resnet101-30epochs.onnx"
9
- onnx_model_vgg16_path = "./vgg16-20epochs.onnx"
10
-
11
- labels = ['Ajloun Castle', 'Hadrians Arch', 'Petra-siq', 'Roman Ruins-Jerash', 'Roman amphitheater', 'The Cardo Maximus of Jerash', 'Wadi Rum', 'petra-Treasury', 'umm qais']
12
-
13
  def predict_image(image_path, model):
14
  if model == "InceptionV3":
15
  img_size = (550, 475)
@@ -47,15 +35,13 @@ def predict_image(image_path, model):
47
  output_name = model_resnet101.get_outputs()[0].name
48
  prediction = model_resnet101.run(None, {input_name: img})
49
 
50
- softmax_output = np.exp(prediction[0][0]) / np.sum(np.exp(prediction[0][0]), axis=-1)
51
- max_confidence = np.max(softmax_output)
52
- predicted_class = np.argmax(softmax_output)
53
 
54
- if max_confidence < 0.2:
55
- return "Hmm, it's a bit tricky. Feel free to add another image, and I'll do my best to make a guess!"
56
 
57
- predicted_label = labels[predicted_class]
58
- return predicted_label
59
 
60
  inputs_image = [
61
  gr.Image(type="filepath", label="Input Image"),
@@ -66,7 +52,7 @@ inputs_image = [
66
  "Resnet101",
67
  ], type="value", label="Select_model")
68
  ]
69
- outputs_text = [gr.Textbox(label="Site")]
70
  interface_image = gr.Interface(
71
  inputs=inputs_image,
72
  fn=predict_image,
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def predict_image(image_path, model):
2
  if model == "InceptionV3":
3
  img_size = (550, 475)
 
35
  output_name = model_resnet101.get_outputs()[0].name
36
  prediction = model_resnet101.run(None, {input_name: img})
37
 
38
+ softmax_output = np.exp(prediction[0][0])
39
+ top_classes = np.argsort(softmax_output)[::-1][:3]
40
+ top_probabilities = softmax_output[top_classes]
41
 
42
+ results = [(labels[class_index], round(probability * 100, 2)) for class_index, probability in zip(top_classes, top_probabilities)]
 
43
 
44
+ return results
 
45
 
46
  inputs_image = [
47
  gr.Image(type="filepath", label="Input Image"),
 
52
  "Resnet101",
53
  ], type="value", label="Select_model")
54
  ]
55
+ outputs_text = [gr.Textbox(label="Top Predictions")]
56
  interface_image = gr.Interface(
57
  inputs=inputs_image,
58
  fn=predict_image,