Pau22 commited on
Commit
9331fda
ยท
verified ยท
1 Parent(s): 3277994

Upload 4 files

Browse files
Files changed (3) hide show
  1. app.py +107 -0
  2. model.weights.h5 +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ from tensorflow.keras.applications import MobileNetV2
7
+ from tensorflow.keras.layers import Dense, BatchNormalization, Dropout
8
+ from tensorflow.keras.models import Sequential
9
+
10
+ # =====================
11
+ # MODEL ARCHITECTURE
12
+ # =====================
13
+
14
+ base_model = MobileNetV2(
15
+ weights=None,
16
+ include_top=False,
17
+ input_shape=(224, 224, 3),
18
+ pooling="avg"
19
+ )
20
+
21
+ model = Sequential([
22
+ base_model,
23
+ BatchNormalization(),
24
+ Dropout(0.5),
25
+ Dense(256, activation="relu"),
26
+ Dropout(0.3),
27
+ Dense(7, activation="softmax")
28
+ ])
29
+
30
+ # Load trained weights
31
+ model.load_weights("model.weights.h5")
32
+
33
+ # =====================
34
+ # CLASS NAMES
35
+ # =====================
36
+
37
+ class_names = [
38
+ "broken_benches",
39
+ "fallen_trees",
40
+ "garbage",
41
+ "leaky_pipes",
42
+ "open_manhole",
43
+ "potholes",
44
+ "streetlight"
45
+ ]
46
+
47
+ # =====================
48
+ # PREDICTION FUNCTION
49
+ # =====================
50
+
51
+ def predict_image(image):
52
+ if image is None:
53
+ return "No image uploaded", "0%"
54
+
55
+ image = image.convert("RGB")
56
+ image = image.resize((224, 224))
57
+
58
+ img = np.array(image, dtype=np.float32) / 255.0
59
+ img = np.expand_dims(img, axis=0)
60
+
61
+ prediction = model.predict(img, verbose=0)
62
+
63
+ predicted_class = class_names[np.argmax(prediction)]
64
+ confidence = float(np.max(prediction))
65
+
66
+ return predicted_class, f"{confidence:.2%}"
67
+
68
+ # =====================
69
+ # UI
70
+ # =====================
71
+
72
+ description = """
73
+ # ๐Ÿ™๏ธ Community Issue Classification System
74
+
75
+ This AI-powered system automatically identifies common civic infrastructure issues from images.
76
+
77
+ ### Detectable Categories
78
+ - ๐Ÿช‘ Broken Benches
79
+ - ๐ŸŒณ Fallen Trees
80
+ - ๐Ÿ—‘๏ธ Garbage
81
+ - ๐Ÿšฐ Leaky Pipes
82
+ - โš ๏ธ Open Manholes
83
+ - ๐Ÿ•ณ๏ธ Potholes
84
+ - ๐Ÿ’ก Streetlight Issues
85
+
86
+ ### Model Information
87
+ - Model: MobileNetV2 Fine-Tuned Classifier
88
+ - Classes: 7
89
+ - Input Size: 224 ร— 224 RGB Images
90
+ - Developer: Pauras More
91
+
92
+ Upload an image below to classify a civic issue.
93
+ """
94
+
95
+ demo = gr.Interface(
96
+ fn=predict_image,
97
+ inputs=gr.Image(type="pil", label="Upload Image"),
98
+ outputs=[
99
+ gr.Textbox(label="Predicted Class"),
100
+ gr.Textbox(label="Confidence")
101
+ ],
102
+ title="Community Issue Classifier",
103
+ description=description,
104
+ flagging_mode="never"
105
+ )
106
+
107
+ demo.launch()
model.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6c84773b74ba6a1d9235e217e11a21a76e5c59339051aff335ffbb28db40d32
3
+ size 10806808
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow==2.20.0
2
+ gradio==6.16.0
3
+ numpy
4
+ pillow
5
+ h5py