lazarusking commited on
Commit
3b2d2d7
1 Parent(s): 0a40676

update get_component to match gradio3.2 nested layouts

Browse files
Files changed (1) hide show
  1. functions.py +37 -19
functions.py CHANGED
@@ -189,7 +189,18 @@ class CommandBuilder():
189
  Parameters:
190
  inputs: layout block
191
  """
192
- return [gr.components.get_component_instance(i, render=True) for i in inputs.children if not hasattr(i, "children")]
 
 
 
 
 
 
 
 
 
 
 
193
 
194
  def setVideoFilters(self, options):
195
  value = self.outputDict.get(options, "-")
@@ -310,7 +321,7 @@ class CommandBuilder():
310
  # return [no_,no_]
311
 
312
 
313
- def mediaChange(option:str)-> List[Component]:
314
  """
315
  Allows playing the media in various options,
316
  Video, Audio or File
@@ -321,9 +332,9 @@ def mediaChange(option:str)-> List[Component]:
321
  Returns:
322
  List[Component]: list of toggled output components to display
323
  """
324
- ops = {"Audio": gr.update(visible=True)}
325
- ops2 = {"Video": gr.update(visible=True)}
326
- ops3 = {"File": gr.update(visible=True, interactive=False)}
327
 
328
  def chosen(x): return x.get(option, gr.update(visible=False))
329
  return [chosen(ops), chosen(ops2), chosen(ops3)]
@@ -466,20 +477,27 @@ class Clear(CommandBuilder):
466
  self._component = []
467
  if input_component is not None:
468
  for i in input_component:
469
- self._component += super()._get_component_instance(i)
470
-
471
- # def __get_component_instance(self, inputs: gr.Blocks) -> list:
472
- # # print(inputs, " class instance")
473
- # # res=[]
474
- # # for i in inputs.children:
475
- # # print(hasattr(i,"children"))
476
- # # if not (hasattr(i,"children")):
477
- # # res.append(gr.components.get_component_instance(i,render=True))
478
- # # print(i)
479
- # # elif hasattr(i,"children"):
480
- # # continue
481
- # # return res
482
- # return [gr.components.get_component_instance(i, render=True) for i in inputs.children if not hasattr(i, "children")]
 
 
 
 
 
 
 
483
 
484
  def add(self, *args):
485
  print(args, type(args))
 
189
  Parameters:
190
  inputs: layout block
191
  """
192
+ res=[]
193
+ for i in inputs.children:
194
+ # print(i,hasattr(i,"children"))
195
+ if not (hasattr(i,"children")):
196
+ # res.append(gr.components.get_component_instance(i,render=True))
197
+ res+=[gr.components.get_component_instance(i,render=True)]
198
+ # print(res)
199
+ elif hasattr(i,"children"):
200
+ res+=self._get_component_instance(i)
201
+ # print(res)
202
+ return res
203
+ # return [gr.components.get_component_instance(i, render=True) for i in inputs.children if not hasattr(i, "children")]
204
 
205
  def setVideoFilters(self, options):
206
  value = self.outputDict.get(options, "-")
 
321
  # return [no_,no_]
322
 
323
 
324
+ def mediaChange(option:str,state)-> List[Component]:
325
  """
326
  Allows playing the media in various options,
327
  Video, Audio or File
 
332
  Returns:
333
  List[Component]: list of toggled output components to display
334
  """
335
+ ops = {"Audio": gr.update(visible=True,value=state)}
336
+ ops2 = {"Video": gr.update(visible=True,value=state)}
337
+ ops3 = {"File": gr.update(visible=True,value=state, interactive=False)}
338
 
339
  def chosen(x): return x.get(option, gr.update(visible=False))
340
  return [chosen(ops), chosen(ops2), chosen(ops3)]
 
477
  self._component = []
478
  if input_component is not None:
479
  for i in input_component:
480
+ # self._component += super()._get_component_instance(i)
481
+ self._component += self.__get_component_instance(i)
482
+
483
+ def __get_component_instance(self, inputs: gr.Blocks) -> list:
484
+ # print(inputs, " class instance")
485
+ res=[]
486
+ # print(*inputs.children)
487
+ for i in inputs.children:
488
+ # print(i,hasattr(i,"children"))
489
+ if not (hasattr(i,"children")):
490
+ # res.append(gr.components.get_component_instance(i,render=True))
491
+ res+=[gr.components.get_component_instance(i,render=True)]
492
+ # print(i)
493
+ elif hasattr(i,"children"):
494
+ # print(*i.children)
495
+ res+=self.__get_component_instance(i)
496
+ # res=[gr.components.get_component_instance(i, render=True) for i in inputs.children if not hasattr(i, "children")]
497
+ # print(res,"__ result")
498
+ # print(res)
499
+ return res
500
+ # return [gr.components.get_component_instance(i, render=True) for i in inputs.children if not hasattr(i, "children")]
501
 
502
  def add(self, *args):
503
  print(args, type(args))