File size: 1,612 Bytes
dfd5424
 
 
 
 
 
2af65c2
 
 
dfd5424
 
 
 
 
 
 
 
 
 
 
 
2af65c2
dfd5424
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
"""
Patch gradio_client/utils.py para tratar schema=bool em get_type().
JSON Schema permite additionalProperties: false (bool), mas gradio_client assume dict.
"""
import re

path = "/usr/local/lib/python3.11/site-packages/gradio_client/utils.py"
with open(path) as f:
    src = f.read()

# Encontra a definição de get_type (pode estar indentada) e injeta guard no início
# Antes:  def get_type(schema):
# Depois: def get_type(schema):
#             if not isinstance(schema, dict): return "Any"
patched = re.sub(
    r'([ \t]*def get_type\(schema\):\n)',
    r'\1\g<1>    if not isinstance(schema, dict): return "Any"\n'.replace(
        r'\g<1>', ''
    ),
    src,
    count=1,
)

# Fallback: substituição simples se regex falhar
if patched == src:
    for variant in [
        "def get_type(schema):\n",
        "    def get_type(schema):\n",
        "        def get_type(schema):\n",
    ]:
        if variant in src:
            indent = variant[: len(variant) - len(variant.lstrip())]
            guard = f"{indent}    if not isinstance(schema, dict): return \"Any\"\n"
            patched = src.replace(variant, variant + guard, 1)
            print(f"Patched with variant: {repr(variant)}")
            break

if patched == src:
    print("WARNING: pattern not found, printing context around 'get_type':")
    for i, line in enumerate(src.splitlines()):
        if "get_type" in line:
            print(f"  line {i}: {repr(line)}")
    # Não falha o build — app pode funcionar mesmo sem o patch
else:
    with open(path, "w") as f:
        f.write(patched)
    print("gradio_client patched OK")