"""Functional probe for gradio 3.x apps that predate gradio_client: speaks the old protocol directly. usage: probe_legacy.py URL [REPO_DIR] [OUT_DIR] Reads /config, picks the main event (an api_name, or the first click/submit wired to a rich input), builds inputs per component (the Space's own example files when it ships them), and calls it through the websocket queue when the app queues, else POST /api/predict. Same output contract as probe.py: one JSON line per endpoint tried.""" import base64, json, math, re, struct, sys, tempfile, uuid, wave, zlib from pathlib import Path import requests from websockets.sync.client import connect url = sys.argv[1].rstrip("/") + "/" 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 TEXT = __import__("os").environ.get("SD_PROBE_TEXT", "a photo of a red apple on a wooden table") RICH = {"image", "audio", "video", "textbox", "file", "chatbot", "sketchpad", "gallery"} def repo_file(exts): if not repo or not repo.exists(): return None fs = [p for p in repo.rglob("*") if p.is_file() and p.suffix.lower() in exts and ".git" not in p.parts and 2_000 < p.stat().st_size < 5_000_000] fs.sort(key=lambda p: (not re.search(r"example|sample|demo|test|input", str(p), re.I), len(p.parts), str(p))) return fs[0] if fs else None def synth_png(): w = 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)) ch = lambda t, d: struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff) return b"\x89PNG\r\n\x1a\n" + ch(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + ch(b"IDAT", zlib.compress(raw)) + ch(b"IEND", b"") def synth_wav(): p = Path(tempfile.mkdtemp()) / "probe.wav" with wave.open(str(p), "w") as f: f.setnchannels(1); f.setsampwidth(2); f.setframerate(16000) f.writeframes(b"".join(struct.pack("