Spaces:
Build error
Build error
File size: 13,207 Bytes
a13666a 6a61728 f6250e9 13be423 f6250e9 13be423 f6250e9 13be423 f6250e9 13be423 f6250e9 13be423 f6250e9 13be423 f6250e9 443261c 34b6305 c914f42 bf4a2e3 c914f42 bf4a2e3 c914f42 bf4a2e3 c914f42 bf4a2e3 c914f42 bf4a2e3 c914f42 f6250e9 a13666a a5ff98b 1719ed3 a5ff98b 399472f a5ff98b c6b46e5 7b4839f c6b46e5 a5ff98b c6b46e5 a5ff98b f6250e9 1719ed3 a5ff98b 399472f a5ff98b 1719ed3 e2231a0 c6b46e5 50dc7c8 0144708 1719ed3 0144708 c914f42 0144708 26a74a6 73801fb 50dc7c8 73801fb 50dc7c8 73801fb 50dc7c8 73801fb 50dc7c8 73801fb 50dc7c8 73801fb 50dc7c8 73801fb 50dc7c8 a4d00c4 0144708 50dc7c8 0144708 50dc7c8 0144708 50dc7c8 0144708 50dc7c8 0144708 3b8d4eb 982851d 0144708 4886186 c6b46e5 7b4839f ec6171b d179488 c914f42 3b8d4eb ec6171b a13666a c6b46e5 3b8d4eb a13666a 1be4dc8 b1c7b39 e0c6de2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | import onnx
import onnxruntime as ort
import numpy as np
import cv2
import gradio as gr
def location(place):
if place == "Ajloun Castle":
map_link = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d387195.9481044243!2d35.7274499!3d32.3252097!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x151c8888296393d7%3A0xad15bd4bdbfa4a2c!2sAjloun%20Castle!5e0!3m2!1sen!2sus!4v1645602498168!5m2!1sen!2sus"
elif place == "Jerash":
map_link = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d403636.1090892695!2d35.8898159!3d32.2756771!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x151c802ff49ac08d%3A0x876c24b1cbded302!2sJerash!5e0!3m2!1sen!2sus!4v1645603957293!5m2!1sen!2sus"
elif place == "Petra":
map_link = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d403636.1090892695!2d35.4665137!3d30.3200019!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x15016930021ab6b1%3A0xe43a697bc3a3e0b9!2sWadi+Musa!5e0!3m2!1sen!2sus!4v1645604690535!5m2!1sen!2sus"
elif place == "Roman amphitheater":
map_link = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d403636.1090892695!2d35.9368315!3d31.9517165!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x151ca07139c70a21%3A0xc5b2f8903093b109!2sRoman+Theater!5e0!3m2!1sen!2sus!4v1645605382663!5m2!1sen!2sus"
elif place == "Umm Qais":
map_link = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d403636.1090892695!2d35.6698552!3d32.6625169!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x151c6d07287b7199%3A0x96d0d420e01bf0b1!2sUmm+Qais!5e0!3m2!1sen!2sus!4v1645606064411!5m2!1sen!2sus"
elif place == "Wadi Rum":
map_link = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d403636.1090892695!2d35.3964418!3d29.556416!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0:0x0!2sWadi+Rum!5e0!3m2!1sen!2sus!4v1645606782015!5m2!1sen!2sus"
return map_link
def information(place):
if place == "Ajloun Castle":
info = "Ajloun Castle, located in northern Jordan, is a medieval fortress built in the 12th century by the Ayyubids. It played a strategic role in defending against Crusader invasions and offers panoramic views of the surrounding landscape. The castle showcases impressive architecture and is a key historical site in the Ajloun region."
elif place == "Jerash":
info = "Jerash, situated in northern Jordan, is renowned for its well-preserved ancient Roman ruins, including a magnificent oval-shaped forum, triumphal arch, and grand colonnaded street. With origins dating back to the Hellenistic period, Jerash flourished as a Roman city and is now one of the best-preserved provincial Roman cities in the world, attracting visitors with its rich history and architectural splendor. The site provides a captivating glimpse into daily life during the Roman Empire."
elif place == "Petra":
info = "Petra, located in southern Jordan, is a UNESCO World Heritage site famous for its rose-red rock-cut architecture and intricate archaeological wonders. Carved into the cliffs by the Nabataeans around 300 BCE, the ancient city features iconic structures such as Al-Khazneh (The Treasury) and the Monastery, showcasing a unique blend of Hellenistic, Roman, and Arabian influences. Petra's historical significance and breathtaking beauty make it a must-visit destination for travelers and history enthusiasts alike."
elif place == "Roman amphitheater":
info = "Roman Amphitheater, situated in Amman, Jordan, is a well-preserved ancient structure dating back to the 2nd century CE. This impressive amphitheater, capable of seating thousands, was a venue for various performances, including gladiator contests and theatrical productions. With its commanding presence in downtown Amman, the Roman Amphitheater stands as a testament to the city rich history and Roman influence, offering visitors a glimpse into the cultural life of the ancient past."
elif place == "Umm Qais":
info = "Umm Qais, located in northern Jordan, is an archaeological site known for its Greco-Roman ruins. Once part of the Decapolis league, the city features well-preserved remnants, including a theater, basilica, and colonnaded streets. Offering panoramic views of the Sea of Galilee and the Golan Heights, Umm Qais provides a fascinating journey through its historical layers, showcasing the influence of various civilizations, including the Romans and Byzantines."
elif place == "Wadi Rum":
info = "Wadi Rum, also known as the Valley of the Moon, is a vast desert wilderness in southern Jordan characterized by stunning red sandstone mountains and unique rock formations. Inhabited by Bedouins for centuries, Wadi Rum offers a captivating landscape featured in various films. Visitors can explore the surreal desert terrain, go on jeep tours, or experience traditional Bedouin hospitality in a tranquil setting. Wadi Rum stands as a natural wonder, inviting travelers to immerse themselves in its awe-inspiring beauty and cultural richness."
return info
def links_info(place):
if place == "Ajloun Castle":
link = ["https://www.tripadvisor.com/RestaurantsNear-g293988-d1549575-Ajloun_Castle-Jerash_Jerash_Governorate.html","https://www.booking.com/hotel/jo/al-jabal-castle-ajloun.html","https://www.gettyimages.ae/photos/ajloun-castle?assettype=image&sort=mostpopular&phrase=Ajloun%20Castle&license=rf%2Crm"]
elif place == "Jerash":
link = ["https://www.tripadvisor.com/Restaurants-g293988-Jerash_Jerash_Governorate.html","https://www.booking.com/city/jo/jarash.html","https://www.gettyimages.ae/photos/jerash?assettype=image&phrase=Jerash&sort=mostpopular&license=rf%2Crm"]
elif place == "Petra":
link = ["https://www.tripadvisor.com/Restaurants-g318895-Petra_Wadi_Musa_Ma_an_Governorate.html","https://www.booking.com/region/jo/petra.html","https://www.gettyimages.ae/photos/petra?assettype=image&phrase=Petra&sort=mostpopular&license=rf%2Crm"]
elif place == "Roman amphitheater":
link = ["https://www.tripadvisor.com/RestaurantsNear-g293986-d319450-Roman_Theatre-Amman_Amman_Governorate.html","https://www.tripadvisor.com/HotelsNear-g293986-d319450-Roman_Theatre-Amman_Amman_Governorate.html","https://www.gettyimages.ae/photos/roman-amphitheater-amman?assettype=image&phrase=Roman%20amphitheater%20Amman&sort=mostpopular&license=rf%2Crm"]
elif place == "Umm Qais":
link = ["https://www.tripadvisor.com/Restaurants-g318874-Umm_Qais_Irbid_Governorate.html","https://www.booking.com/city/jo/umm-qays.html","https://www.gettyimages.ae/photos/umm-qais?assettype=image&phrase=Umm%20Qais&sort=mostpopular&license=rf%2Crm"]
elif place == "Wadi Rum":
link = ["https://www.tripadvisor.com/Restaurants-g303973-Wadi_Rum_Al_Aqabah_Governorate.html","https://www.booking.com/city/jo/wadi-rum.html","https://www.gettyimages.ae/photos/wadi-rum?assettype=image&phrase=Wadi%20Rum&sort=mostpopular&license=rf%2Crm"]
return link
def load_image_with_cv2(image_path):
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (224, 224))
img_array = img.astype(np.float32) / 255.0
img_array = np.expand_dims(img_array, axis=0)
return img_array
def open_model(model_selection):
if model_selection == "VGG19":
return './models/VGG19_32_onnx.onnx'
elif model_selection == "ResNet50":
return './models/ResNet50_32_onnx.onnx'
elif model_selection == "Efficientnet":
return './models/efficientnet_32_onnx.onnx'
elif model_selection == "InceptionV3":
return './models/last_inceptionV3.onnx'
def classify_image(input_image,model_selection):
img_array = load_image_with_cv2(input_image)
ort_sess = ort.InferenceSession(open_model(model_selection))
input_name = ort_sess.get_inputs()[0].name
output_name = ort_sess.get_outputs()[0].name
outputs = ort_sess.run(None, {input_name: img_array})
predicted_class_index = np.argmax(outputs[0][0])
classes = ['Ajloun Castle', 'Jerash', 'Jerash', 'Petra', 'Roman amphitheater', 'Umm Qais', 'Wadi Rum']
predicted_class = classes[predicted_class_index]
confidence = max(outputs[0][0])
return predicted_class, confidence
def show_preds_image(image_path,model_selection):
mux_value = str(classify_image(image_path,model_selection)[0])
if float(classify_image(image_path,model_selection)[1])>0.85:
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (224, 224))
height, width, _ = img.shape
#text_x = int((width - len(mux_value) * 10) / 2)
#text_y = int(height / 2)
font_scale = 1
text_size = cv2.getTextSize(mux_value, cv2.FONT_HERSHEY_SIMPLEX, fontScale=font_scale, thickness=2)[0]
text_x = 10
text_y = text_size[1] + 10
cv2.putText(img, mux_value, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, font_scale, (255, 0, 0), 2, cv2.LINE_AA)
conf = (classify_image(image_path,model_selection))
informations = information(mux_value)
map_link = location(mux_value)
links = links_info(mux_value)
google_map = f'''
<!DOCTYPE html>
<html>
<head>
<title>Map Display</title>
</head>
<body>
<h1>Map Display</h1>
<iframe width="600" height="450" frameborder="0" style="border:0" src="{map_link}" allowfullscreen></iframe>
</body>
</html>
'''
link_info = f'''
<!DOCTYPE html>
<html>
<head>
<title>Links</title>
</head>
<body>
<h1>Useful Links</h1>
<ul>
<li>Restaurants : <a href="{links[0]}" target="_blank">{links[0]}</a></li>
<li>Hotels : <a href="{links[1]}" target="_blank">{links[1]}</a></li>
<li>Images : <a href="{links[2]}" target="_blank">{links[2]}</a></li>
</ul>
</body>
</html>
'''
return img,conf,informations,link_info,google_map
elif 0.3 <float(classify_image(image_path,model_selection)[1])<0.85:
mux_value = str(classify_image(image_path,model_selection)[0])
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (224, 224))
conf = (classify_image(image_path,model_selection))
informations = "I'm not sure pls try another input it may be true"
map_link = location(mux_value)
links = links_info(mux_value)
google_map = f'''
<!DOCTYPE html>
<html>
<head>
<title>Map Display</title>
</head>
<body>
<h1>Map Display</h1>
<iframe width="600" height="450" frameborder="0" style="border:0" src="{map_link}" allowfullscreen></iframe>
</body>
</html>
'''
link_info = f'''
<!DOCTYPE html>
<html>
<head>
<title>Links</title>
</head>
<body>
<h1>Useful Links</h1>
<ul>
<li>Restaurants : <a href="{links[0]}" target="_blank">{links[0]}</a></li>
<li>Hotels : <a href="{links[1]}" target="_blank">{links[1]}</a></li>
<li>Images : <a href="{links[2]}" target="_blank">{links[2]}</a></li>
</ul>
</body>
</html>
'''
return img,conf,informations,link_info,google_map
elif 0.0 <float(classify_image(image_path,model_selection)[1])<0.3:
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (224, 224))
conf = (classify_image(image_path,model_selection))
informations = "Wronge input pls try another input"
link_info = f'''
<!DOCTYPE html>
<html>
<head>
<title>Links</title>
</head>
<body>
<h1>NO link provide pls try another input</h1>
</body>
</html>
'''
google_map = f'''
<!DOCTYPE html>
<html>
<head>
<title>Map Display pls try another input</title>
</head>
<body>
<h1>No location pls try another input</h1>
</body>
</html>
'''
return img,conf,informations,link_info,google_map
inputs_image = gr.Image(type="filepath", label="Input Image")
model_selection = gr.Dropdown(["VGG19","InceptionV3","ResNet50","Efficientnet"],label="Model selection")
outputs_image = gr.Image(type="numpy", label="Output Image")
output_text = gr.Textbox(label="prediction & confidence")
inform = gr.Textbox(label="Information about the place")
g_map = gr.HTML(label="Place location")
info_html = gr.HTML()
interface_image = gr.Interface(
fn=show_preds_image,
inputs=[inputs_image,model_selection],
outputs=[outputs_image,output_text,inform,info_html,g_map],
title="image classification",
)
interface_image.launch()
#Abdullah jarrah.
|