File size: 2,548 Bytes
0977298
 
 
 
a74b3de
 
0977298
 
 
 
 
 
 
 
8f5e920
0977298
 
 
 
 
89721ec
0977298
 
8b2c3c7
0977298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89721ec
8dd7bf1
f4e2659
51cbf4e
0977298
0fc9707
 
89721ec
16dec41
0977298
 
e07c288
0977298
15bd719
0fc9707
0977298
 
0fc9707
0977298
 
 
23c4660
39bedb1
0977298
2e33a22
 
 
 
 
39bedb1
2e33a22
 
0977298
 
 
 
 
 
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
import gradio as gr
import cv2
import numpy as np
from tensorflow.keras.models import load_model



class_folders = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]

Inception_path='./Models/inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'
VGGNet_path='./Models/vgg_16_-saved-model-89-acc-0.93.hdf5'
ResNet_path= './Models/resnet50-saved-model-79-val_acc-1.00.hdf5'
EfficientNet_path= './Models/efficientnet-saved-model-06-val_acc-0.98.hdf5'


Inception_model = load_model(Inception_path)
VGGNet_model = load_model(VGGNet_path)
ResNet_model = load_model(ResNet_path)
Efficient_model = load_model(EfficientNet_path)

history=[]
def classify_selected_model(image, model_name):
    try:
        
        img = cv2.imread(image)
        img = cv2.resize(img, (150, 150))
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = np.expand_dims(img, axis=0)

        if model_name == "ResNet":
            predictions = ResNet_model.predict(img)
        elif model_name == "EfficientNet":
            predictions = Efficient_model.predict(img)
        elif model_name == "VGGNet":
            predictions = VGGNet_model.predict(img)
        elif model_name == "InceptionV3":
            predictions = Inception_model.predict(img)

        class_index = np.argmax(predictions[0])
        class_name = class_folders[class_index]
        probability = round(max(predictions[0]) * 100, 2)
        
        
        result_str = f" {model_name} : {class_name}  {probability}%  "
        history.append(result_str)
        
        return class_name, probability, history[-3:-1]
        
    except Exception as e:
        error_message = f"Error: {str(e)}"
        return None, None, None
    
        

image_input = gr.Image(type='filepath', label="Input Image")
model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")
result_textbox = gr.Textbox("Results", label="history Results")

iface = gr.Interface(
    fn=classify_selected_model,
    inputs=[image_input, model_dropdown ,],
    outputs=[
        gr.Label(value="Archaeological Site"), 
        gr.Label(value="Probability"),
        result_textbox],
    
    examples=[
        ["Sites/Ajloun.png" ],
        ["Sites/Jeresh.png"],
        ["Sites/Umm Qais.png"],
        ["Sites/Petra.png"],
        ["Sites/Roman Amphitheater.png"],
        ["Sites/Wadi Rum.png"]] ,

       
    live=True,
    title="Image Classification for Archaeological Sites Interface",
    
)

iface.launch(debug=True, share=True )