Kedar Dabhadkar commited on
Commit
ade8ae7
1 Parent(s): 81cadb0

Update script

Browse files
Files changed (2) hide show
  1. fast_dash_app.py +26 -10
  2. fastapp.py +0 -42
fast_dash_app.py CHANGED
@@ -1,25 +1,41 @@
 
1
  from fast_dash import FastDash, UploadImage, Image, Upload
2
  import PIL
3
  import numpy as np
 
4
  from app import func
5
  import tempfile
6
  import base64
7
 
8
- def generate_image(input_tiff_image: Upload) -> (Image, Image):
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- with tempfile.NamedTemporaryFile(delete=False) as f:
11
- contents = input_tiff_image.encode("utf8").split(b";base64,")[1]
12
- f.write(base64.decodebytes(contents))
 
 
13
 
14
- input_image, output_image = func(f)
15
 
16
- # Convert numpy arrays to PIL images
17
- input_image = PIL.Image.fromarray(np.uint8(input_image)).convert('RGB')
18
- output_image = PIL.Image.fromarray(np.uint8(output_image)).convert('RGB')
19
 
20
- return input_image, output_image
21
 
22
- app = FastDash(generate_image, port=8000)
23
  server = app.server
24
 
25
  if __name__ == "__main__":
 
1
+ import os
2
  from fast_dash import FastDash, UploadImage, Image, Upload
3
  import PIL
4
  import numpy as np
5
+
6
  from app import func
7
  import tempfile
8
  import base64
9
 
10
+ examples = ["India_900498_S2Hand", "Spain_7370579_S2Hand", "USA_430764_S2Hand"]
11
+
12
+ def detect_water(select_an_example: str = examples, input_tiff_image: Upload = None) -> (Image, Image):
13
+ """
14
+ NASA and IBM recently uploaded their foundation model on Hugging Face, Pritivi, at https://huggingface.co/ibm-nasa-geospatial.
15
+ This demo, built with Fast Dash, showcases a version of Prithvi that they finetuned to detect water from satellite images.
16
+ Select an example or upload your own TIFF image.
17
+ If uploading your own image, read the format details at https://huggingface.co/ibm-nasa-geospatial/Prithvi-100M-sen1floods11.
18
+ """
19
+
20
+ # If example is selected
21
+ if input_tiff_image is None:
22
+ input_satellite_image = PIL.Image.open(os.path.join("examples", f"{select_an_example}.png"))
23
+ water_prediction_mask = PIL.Image.open(os.path.join("examples", f"{select_an_example}_result.png"))
24
 
25
+ # If file is uploaded, run inference
26
+ else:
27
+ with tempfile.NamedTemporaryFile(delete=False) as f:
28
+ contents = input_tiff_image.encode("utf8").split(b";base64,")[1]
29
+ f.write(base64.decodebytes(contents))
30
 
31
+ input_satellite_image, water_prediction_mask = func(f)
32
 
33
+ input_satellite_image = PIL.Image.fromarray(np.uint8(input_satellite_image)).convert('RGB')
34
+ water_prediction_mask = PIL.Image.fromarray(np.uint8(water_prediction_mask)).convert('RGB')
 
35
 
36
+ return input_satellite_image, water_prediction_mask
37
 
38
+ app = FastDash(detect_water, theme="cosmo", port=7860)
39
  server = app.server
40
 
41
  if __name__ == "__main__":
fastapp.py DELETED
@@ -1,42 +0,0 @@
1
- import os
2
- from fast_dash import FastDash, UploadImage, Image, Upload
3
- import PIL
4
- import numpy as np
5
-
6
- from app import func
7
- import tempfile
8
- import base64
9
-
10
- examples = ["India_900498_S2Hand", "Spain_7370579_S2Hand", "USA_430764_S2Hand"]
11
-
12
- def detect_water(select_an_example: str = examples, input_tiff_image: Upload = None) -> (Image, Image):
13
- """
14
- NASA and IBM recently uploaded their foundation model on Hugging Face, Pritivi, at https://huggingface.co/ibm-nasa-geospatial.
15
- This demo, built with Fast Dash, showcases a version of Prithvi that they finetuned to detect water from satellite images.
16
- Select an example or upload your own TIFF image.
17
- If uploading your own image, read the format details at https://huggingface.co/ibm-nasa-geospatial/Prithvi-100M-sen1floods11.
18
- """
19
-
20
- # If example is selected
21
- if input_tiff_image is None:
22
- input_satellite_image = PIL.Image.open(os.path.join("examples", f"{select_an_example}.png"))
23
- water_prediction_mask = PIL.Image.open(os.path.join("examples", f"{select_an_example}_result.png"))
24
-
25
- # If file is uploaded, run inference
26
- else:
27
- with tempfile.NamedTemporaryFile(delete=False) as f:
28
- contents = input_tiff_image.encode("utf8").split(b";base64,")[1]
29
- f.write(base64.decodebytes(contents))
30
-
31
- input_satellite_image, water_prediction_mask = func(f)
32
-
33
- input_satellite_image = PIL.Image.fromarray(np.uint8(input_satellite_image)).convert('RGB')
34
- water_prediction_mask = PIL.Image.fromarray(np.uint8(water_prediction_mask)).convert('RGB')
35
-
36
- return input_satellite_image, water_prediction_mask
37
-
38
- app = FastDash(detect_water, theme="cosmo", port=7860)
39
- server = app.server
40
-
41
- if __name__ == "__main__":
42
- app.run()