Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,43 @@
|
|
| 1 |
import yaml
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
#
|
| 5 |
import gradio as gr
|
| 6 |
from functools import wraps
|
|
|
|
| 7 |
|
| 8 |
-
def
|
|
|
|
|
|
|
|
|
|
| 9 |
@wraps(original_init)
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
from smolagents import GradioUI, CodeAgent, InferenceClientModel
|
| 24 |
|
| 25 |
# Get current directory path
|
|
|
|
| 1 |
import yaml
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Ultimate Gradio compatibility fix - dynamically filter kwargs based on component signatures
|
| 5 |
import gradio as gr
|
| 6 |
from functools import wraps
|
| 7 |
+
import inspect
|
| 8 |
|
| 9 |
+
def patch_gradio_component(component_class):
|
| 10 |
+
"""Patch a Gradio component to accept only supported kwargs"""
|
| 11 |
+
original_init = component_class.__init__
|
| 12 |
+
|
| 13 |
@wraps(original_init)
|
| 14 |
+
def patched_init(self, *args, **kwargs):
|
| 15 |
+
try:
|
| 16 |
+
sig = inspect.signature(original_init)
|
| 17 |
+
# Filter kwargs to only include parameters the original __init__ accepts
|
| 18 |
+
valid_params = set(sig.parameters.keys())
|
| 19 |
+
filtered_kwargs = {k: v for k, v in kwargs.items() if k in valid_params or
|
| 20 |
+
any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values())}
|
| 21 |
+
return original_init(self, *args, **filtered_kwargs)
|
| 22 |
+
except Exception as e:
|
| 23 |
+
# Fallback to original call
|
| 24 |
+
try:
|
| 25 |
+
return original_init(self, *args, **kwargs)
|
| 26 |
+
except TypeError:
|
| 27 |
+
# Last resort - call with no kwargs
|
| 28 |
+
return original_init(self, *args)
|
| 29 |
+
|
| 30 |
+
component_class.__init__ = patched_init
|
| 31 |
+
return component_class
|
| 32 |
+
|
| 33 |
+
# Patch all Gradio components
|
| 34 |
+
for name in dir(gr):
|
| 35 |
+
try:
|
| 36 |
+
obj = getattr(gr, name)
|
| 37 |
+
if inspect.isclass(obj) and hasattr(obj, '__init__'):
|
| 38 |
+
patch_gradio_component(obj)
|
| 39 |
+
except:
|
| 40 |
+
pass
|
| 41 |
from smolagents import GradioUI, CodeAgent, InferenceClientModel
|
| 42 |
|
| 43 |
# Get current directory path
|