main
py 54 lines 1.64 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import os
5
6 import pybase64 as base64
7 import requests
8
9 # This example shows how to perform an online inference that generates
10 # multimodal data. In this specific case this example will take a geotiff
11 # image as input, process it using the multimodal data processor, and
12 # perform inference.
13 # Requirements :
14 # - install TerraTorch v1.1 (or later):
15 # pip install terratorch>=v1.1
16 # - start vllm in serving mode with the below args
17 # --model='ibm-nasa-geospatial/Prithvi-EO-2.0-300M-TL-Sen1Floods11'
18 # --skip-tokenizer-init --enforce-eager
19 # --io-processor-plugin terratorch_segmentation
20 # --enable-mm-embeds
21
22
23 def main():
24 image_url = "https://huggingface.co/christian-pinto/Prithvi-EO-2.0-300M-TL-VLLM/resolve/main/valencia_example_2024-10-26.tiff" # noqa: E501
25 server_endpoint = "http://localhost:8000/pooling"
26
27 request_payload_url = {
28 "data": {
29 "data": image_url,
30 "data_format": "url",
31 "image_format": "tiff",
32 "out_data_format": "b64_json",
33 },
34 "priority": 0,
35 "model": "ibm-nasa-geospatial/Prithvi-EO-2.0-300M-TL-Sen1Floods11",
36 }
37
38 ret = requests.post(server_endpoint, json=request_payload_url)
39
40 print(f"response.status_code: {ret.status_code}")
41 print(f"response.reason:{ret.reason}")
42
43 response = ret.json()
44
45 decoded_image = base64.b64decode(response["data"]["data"])
46
47 out_path = os.path.join(os.getcwd(), "online_prediction.tiff")
48
49 with open(out_path, "wb") as f:
50 f.write(decoded_image)
51
52
53 if __name__ == "__main__":
54 main()