github-actions[bot] commited on
Commit
c5ece02
·
1 Parent(s): 5fba806

Deploy from GitHub - 2026-01-21 07:08:41

Browse files
Files changed (1) hide show
  1. app.py +50 -12
app.py CHANGED
@@ -14,6 +14,56 @@ Based on Johnson et al. "Perceptual Losses for Real-Time Style Transfer"
14
  https://arxiv.org/abs/1603.08155
15
  """
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  import gradio as gr
18
  import torch
19
  import torch.nn as nn
@@ -29,18 +79,6 @@ from collections import deque
29
  import tempfile
30
  import json
31
 
32
- # Workaround for gradio_client bug with dict schemas
33
- try:
34
- from gradio_client import client_utils
35
- original_get_type = client_utils.get_type
36
- def patched_get_type(schema):
37
- if isinstance(schema, bool):
38
- return "bool" if schema else "Any"
39
- return original_get_type(schema)
40
- client_utils.get_type = patched_get_type
41
- except Exception:
42
- pass # Skip patching if structure is different
43
-
44
  # Try to import plotly for charts
45
  try:
46
  import plotly.graph_objects as go
 
14
  https://arxiv.org/abs/1603.08155
15
  """
16
 
17
+ # ============================================================================
18
+ # PATCH gradio_client BEFORE importing gradio
19
+ # This fixes a bug where schema can be a bool (False means "any type")
20
+ # ============================================================================
21
+ import sys
22
+
23
+ def _patched_get_type(schema):
24
+ """Patched version that handles when schema is a bool (False for any type)"""
25
+ if isinstance(schema, bool):
26
+ return "Any" if not schema else "bool"
27
+ if not isinstance(schema, dict):
28
+ return str(type(schema).__name__)
29
+ if "const" in schema:
30
+ return f"Literal[{repr(schema['const'])}]"
31
+ if "enum" in schema:
32
+ return f"Literal[{', '.join(repr(v) for v in schema['enum'])}]"
33
+ if "$ref" in schema:
34
+ ref = schema["$ref"]
35
+ if ref.startswith("#/$defs/"):
36
+ return ref.split("/")[-1]
37
+ return ref
38
+ if "type" in schema:
39
+ t = schema["type"]
40
+ if t == "string":
41
+ return "str"
42
+ elif t == "number":
43
+ return "float"
44
+ elif t == "integer":
45
+ return "int"
46
+ elif t == "boolean":
47
+ return "bool"
48
+ elif t == "array":
49
+ if "items" in schema:
50
+ items_type = _patched_get_type(schema["items"])
51
+ return f"list[{items_type}]"
52
+ return "list"
53
+ elif t == "object":
54
+ if "additionalProperties" in schema:
55
+ items_type = _patched_get_type(schema["additionalProperties"])
56
+ return f"dict[str, {items_type}]"
57
+ return "dict"
58
+ return "Any"
59
+
60
+ # Pre-patch by installing in sys.modules before gradio imports it
61
+ import types
62
+ mock_client_utils = types.ModuleType('gradio_client.utils')
63
+ mock_client_utils.get_type = _patched_get_type
64
+ sys.modules['gradio_client.utils'] = mock_client_utils
65
+
66
+ # Now safe to import gradio
67
  import gradio as gr
68
  import torch
69
  import torch.nn as nn
 
79
  import tempfile
80
  import json
81
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  # Try to import plotly for charts
83
  try:
84
  import plotly.graph_objects as go