@@ -206,10 +206,9 @@ def __init__(self):
206
206
)
207
207
208
208
209
- def flatten_attributes (component_group , absolute_name : str , d = None ) -> OrderedDict :
210
- if d is None :
211
- d = OrderedDict ()
212
-
209
+ def flatten_attributes (
210
+ component_group , absolute_name : str , d : OrderedDict
211
+ ) -> OrderedDict :
213
212
if not hasattr (component_group , "__dict__" ):
214
213
return d
215
214
@@ -218,14 +217,14 @@ def flatten_attributes(component_group, absolute_name: str, d=None) -> OrderedDi
218
217
if name .startswith ("_" ):
219
218
# Private attribute
220
219
continue
221
- elif elem in component_group . __dict__ .values ():
220
+ elif elem in d .values ():
222
221
# Don't duplicate any tiems
223
222
continue
224
223
elif isinstance (elem , Component ):
225
224
# Only add components to dict
226
225
d [new_absolute_name ] = elem
227
226
else :
228
- d = flatten_attributes (elem , new_absolute_name , d = d )
227
+ flatten_attributes (elem , new_absolute_name , d )
229
228
230
229
return d
231
230
@@ -250,26 +249,35 @@ def __init__(self, demo: gr.Blocks) -> None:
250
249
show_progress = False ,
251
250
)
252
251
252
+ ignore = ["df" , "predictions_plot" ]
253
253
self .run .click (
254
- create_processing_function (self , ignore = ["df" , "predictions_plot" ]),
255
- inputs = list (flatten_attributes (self , "interface" ).values ()),
254
+ create_processing_function (self , ignore = ignore ),
255
+ inputs = [
256
+ v
257
+ for k , v in flatten_attributes (self , "interface" , OrderedDict ()).items ()
258
+ if last_part (k ) not in ignore
259
+ ],
256
260
outputs = [self .results .df , self .results .predictions_plot ],
257
261
show_progress = True ,
258
262
)
259
263
260
264
265
+ def last_part (k : str ) -> str :
266
+ return k .split ("." )[- 1 ]
267
+
268
+
261
269
def create_processing_function (interface : AppInterface , ignore = []):
262
- d = flatten_attributes (interface , "interface" )
263
- keys = [k .split ("." )[- 1 ] for k in d .keys ()]
264
- keys = [k for k in keys if k not in ignore ]
270
+ d = flatten_attributes (interface , "interface" , OrderedDict ())
271
+ keys = [k for k in map (last_part , d .keys ()) if k not in ignore ]
265
272
_ , idx , counts = np .unique (keys , return_index = True , return_counts = True )
266
273
if np .any (counts > 1 ):
267
274
raise AssertionError ("Bad keys: " + "," .join (np .array (keys )[idx [counts > 1 ]]))
268
275
269
- def f (components ):
276
+ def f (* components ):
270
277
n = len (components )
271
278
assert n == len (keys )
272
- return processing (** {keys [i ]: components [i ] for i in range (n )})
279
+ for output in processing (** {keys [i ]: components [i ] for i in range (n )}):
280
+ yield output
273
281
274
282
return f
275
283
0 commit comments