Alif Al Hasan commited on
Commit
1424103
·
1 Parent(s): e58ca2a

[Task] Model Deployment

Browse files

[Description] Initial Deployment of the model.
[Author]

@alifalhasan

app.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src.classify.classify import classify_logo
3
+
4
+ if __name__ == "__main__":
5
+ # Create the Gradio interface
6
+ iface = gr.Interface(
7
+ fn=classify_logo,
8
+ inputs=[gr.Image(type="filepath")],
9
+ outputs=gr.Textbox(label="Predicted class")
10
+ )
11
+
12
+ # Launch the interface
13
+ iface.launch(share=True)
flagged/image_file/0241897a7b97af036402/arsenal.png ADDED
flagged/image_file/11b334fd25d35a4399a3/arsenal.png ADDED
flagged/image_file/22e0c55976b127358232/arsenal.png ADDED
flagged/image_file/392154eff274987c347e/arsenal.png ADDED
flagged/image_file/46b5bc411c2037dec67a/arsenal.png ADDED
flagged/image_file/6e1a7134efc60a0f7f84/arsenal.png ADDED
flagged/image_file/e738d68c7eea5642416a/arsenal.png ADDED
flagged/log.csv ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ image_file,output,flag,username,timestamp
2
+ "{""path"":""flagged\\image_file\\0241897a7b97af036402\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\6de795593f21b8d7a13da285587d95c0f2cb56e1\\arsenal.png"",""size"":213946,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 13:51:51.930046
3
+ "{""path"":""flagged\\image_file\\22e0c55976b127358232\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\6de795593f21b8d7a13da285587d95c0f2cb56e1\\arsenal.png"",""size"":213946,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 13:51:53.897584
4
+ "{""path"":""flagged\\image_file\\6e1a7134efc60a0f7f84\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\90eac5362cf4c9612ee37f3436f2612954cc6327\\arsenal.png"",""size"":41502,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 14:04:38.780049
5
+ "{""path"":""flagged\\image_file\\392154eff274987c347e\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\90eac5362cf4c9612ee37f3436f2612954cc6327\\arsenal.png"",""size"":41502,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 14:04:40.283244
6
+ "{""path"":""flagged\\image_file\\11b334fd25d35a4399a3\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\90eac5362cf4c9612ee37f3436f2612954cc6327\\arsenal.png"",""size"":41502,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 14:04:41.448505
7
+ "{""path"":""flagged\\image_file\\e738d68c7eea5642416a\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\90eac5362cf4c9612ee37f3436f2612954cc6327\\arsenal.png"",""size"":41502,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 14:04:42.925141
8
+ "{""path"":""flagged\\image_file\\46b5bc411c2037dec67a\\arsenal.png"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\HP\\AppData\\Local\\Temp\\gradio\\90eac5362cf4c9612ee37f3436f2612954cc6327\\arsenal.png"",""size"":41502,""orig_name"":""arsenal.png"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2024-01-03 14:09:47.459632
setup.py DELETED
File without changes
src/{app → classify}/__inti__.py RENAMED
File without changes
src/classify/classify.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """classify.py
2
+
3
+ This module classifies the input image.
4
+
5
+ """
6
+
7
+ import numpy as np
8
+ import tensorflow as tf
9
+ from tensorflow.keras.preprocessing import image
10
+
11
+ # Load the trained model
12
+ import os
13
+
14
+ script_directory = os.path.dirname(os.path.abspath(__file__))
15
+ model_path = os.path.join(script_directory, '../../models/football_logo_model.h5')
16
+
17
+ model = tf.keras.models.load_model(model_path)
18
+
19
+ def preprocess_image(img):
20
+ """
21
+ Preprocess the input image for model prediction.
22
+
23
+ Args:
24
+ img: Input image.
25
+
26
+ Returns:
27
+ img: Preprocessed image.
28
+ """
29
+ img = image.img_to_array(img)
30
+ img = np.expand_dims(img, axis=0)
31
+ img /= 255.0
32
+ return img
33
+
34
+ # Define the class names (replace with your actual class names)
35
+ class_names = ['Arsenal', 'Chelsea', 'Liverpool', 'Manchester City', 'Manchester United']
36
+
37
+ def classify_logo(img):
38
+ """
39
+ Classify the football logo in the input image.
40
+
41
+ Args:
42
+ img: Path to the input image.
43
+
44
+ Returns:
45
+ str: The predicted class of the football logo.
46
+ """
47
+ img_path = img
48
+ img = image.load_img(img_path, target_size=(224, 224))
49
+ img = image.img_to_array(img)
50
+ img = preprocess_image(img)
51
+ prediction = model.predict(img)
52
+ predicted_class_index = prediction.argmax(axis=1)[0]
53
+ predicted_class_name = class_names[predicted_class_index] # Map index to name
54
+ return predicted_class_name