som11 commited on
Commit
aa6f0f2
1 Parent(s): 99bfe63

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +74 -0
  2. requirements.txt +4 -0
  3. resnet101_model.zip +3 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import zipfile
2
+ import os
3
+ import gradio as gr
4
+ import numpy as np
5
+ from keras.models import load_model
6
+ from PIL import Image
7
+ from keras.utils import img_to_array
8
+ from keras.applications.resnet import preprocess_input
9
+
10
+
11
+
12
+ zip_path = 'resnet101_model.zip'
13
+
14
+ extract_dir = 'resnet101_model'
15
+
16
+
17
+ if not os.path.isdir(extract_dir):
18
+
19
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
+
21
+ zip_ref.extractall(extract_dir)
22
+
23
+
24
+ model = load_model(os.path.join(extract_dir, 'resnet101_model'))
25
+
26
+
27
+ class_names = ['cloudy', 'desert', 'green_area', 'water']
28
+
29
+
30
+ def predict_image(file_path):
31
+
32
+ with open(file_path, "rb") as f:
33
+
34
+ imageUploadedByUser = Image.open(f)
35
+
36
+ imageUploadedByUser = imageUploadedByUser.resize((224, 224))
37
+
38
+ if imageUploadedByUser.mode != 'RGB':
39
+ imageUploadedByUser = imageUploadedByUser.convert('RGB')
40
+
41
+ image_to_arr = img_to_array(imageUploadedByUser)
42
+
43
+ image_to_arr_preprocess_input = preprocess_input(image_to_arr)
44
+
45
+ image_to_arr_preprocess_input_expand_dims = np.expand_dims(
46
+ image_to_arr_preprocess_input, axis=0)
47
+
48
+ prediction = model.predict(
49
+ image_to_arr_preprocess_input_expand_dims)[0]
50
+
51
+ prediction_argmax = np.argmax(prediction)
52
+
53
+ prediction_final_result = class_names[prediction_argmax]
54
+
55
+ return f'The predicted satellite image is {prediction_final_result}.'
56
+
57
+
58
+ custom_css = """
59
+ .desc { text-align: center; }
60
+ """
61
+
62
+
63
+ interfaceOfGradio = gr.Interface(
64
+ fn=predict_image,
65
+ inputs=gr.File(type="filepath",
66
+ label="Upload Satellite Image", file_count="single"),
67
+ outputs="text",
68
+ description="<p class='desc'>" +
69
+ "Upload a satellite image on the left and see the prediction result on the right." + "</p>",
70
+ css=custom_css
71
+ )
72
+
73
+
74
+ interfaceOfGradio.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ numpy==1.26.4
2
+ tensorflow==2.10.0
3
+ gradio==4.23.0
4
+ keras==2.10.0
resnet101_model.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a03c57bfcd1c949010bd2da9bdc6536d0c94784cbc2b2c4873bbc8ddad3e5c16
3
+ size 303606453