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)