Spaces:
Sleeping
Sleeping
File size: 1,015 Bytes
8d928e8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import gradio as gr
from gradio_client import Client, handle_file
import numpy as np
import rasterio
from rasterio.transform import Affine
from pathlib import Path
data = np.random.randint(0, 65535, (3, 64, 64), dtype=np.uint16)
transform = Affine.translation(0, 0) * Affine.scale(10, -10)
profile = {
'driver': 'GTiff',
'height': 64,
'width': 64,
'count': 3,
'dtype': 'uint16',
'crs': 'EPSG:4326',
'transform': transform,
}
tiff_path = Path("test_input.tif")
with rasterio.open(tiff_path, 'w', **profile) as dst:
dst.write(data)
def process(filepath):
print("Backend received:", filepath)
import shutil
shutil.copy(filepath, "received_file.ext")
return filepath
demo = gr.Interface(fn=process, inputs=gr.Image(type="filepath"), outputs="text")
demo.launch(prevent_thread_lock=True, server_port=7862)
client = Client("http://127.0.0.1:7862")
result = client.predict(filepath=handle_file("test_input.tif"))
print("Client result:", result)
import sys; sys.exit(0)
|