"""Functional probe: call a running Gradio app's main endpoint(s) with inputs built from its API schema. usage: probe.py URL [REPO_DIR] [OUT_DIR] Inputs prefer the Space's own example files (an image/audio file shipped in the repo), else a synthetic one. Helper endpoints (clear buttons, example loaders, lambdas) are tried last. A call only counts as ok if it returns a non-empty result; returned files must exist and be non-empty. Output files are copied to OUT_DIR for review. Prints one JSON line per endpoint tried.""" import json, math, re, shutil, struct, sys, tempfile, wave, zlib from pathlib import Path from gradio_client import Client try: from gradio_client import handle_file except ImportError: # gradio_client < 1.0 (gradio 3.x / early 4.x) takes plain file paths def handle_file(path): return path url = sys.argv[1] repo = Path(sys.argv[2]) if len(sys.argv) > 2 and sys.argv[2] else None outdir = Path(sys.argv[3]) if len(sys.argv) > 3 else None tmp = Path(tempfile.mkdtemp()) IMG_EXT, AUD_EXT, VID_EXT = {".jpg", ".jpeg", ".png", ".webp"}, {".wav", ".mp3", ".flac", ".ogg"}, {".mp4"} def png(path, w=256, h=256): raw = b"".join(b"\x00" + b"".join(bytes((x % 256, y % 256, 128)) for x in range(w)) for y in range(h)) def chunk(t, d): return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff) path.write_bytes(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw)) + chunk(b"IEND", b"")) return path def wav(path, secs=2.0, sr=16000): with wave.open(str(path), "w") as f: f.setnchannels(1); f.setsampwidth(2); f.setframerate(sr) f.writeframes(b"".join(struct.pack("