CISCai commited on
Commit
c7320b2
·
verified ·
1 Parent(s): c028c60

Worked around metadata table selection issue so I could finally enable it

Browse files

Thanks to

@yoonniverse
for reproducing the issue and submitting a [bug report](https://github.com/gradio-app/gradio/issues/9566) that helped me to work around it.

There's still an issue with the table shrinking on scroll, so disabled line-wrapping as that seems to help.

Files changed (1) hide show
  1. app.py +66 -37
app.py CHANGED
@@ -162,11 +162,9 @@ with gr.Blocks(
162
  visible = False,
163
  )
164
 
165
- meta_array = gr.Matrix(
166
  None,
167
  label = "Unsupported",
168
- row_count = (1, "fixed"),
169
- height = "1rem",
170
  interactive = False,
171
  visible = False,
172
  )
@@ -195,7 +193,7 @@ with gr.Blocks(
195
  ],
196
  datatype = ["str", "str", "str"],
197
  column_widths = ["35%", "15%", "50%"],
198
- wrap = True,
199
  interactive = False,
200
  visible = False,
201
  )
@@ -659,7 +657,7 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
659
  meta_string: gr.Textbox(
660
  visible = False,
661
  ),
662
- meta_array: gr.Matrix(
663
  visible = False,
664
  ),
665
  }
@@ -678,7 +676,7 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
678
  visible = False,
679
  ),
680
  file_meta: gr.Matrix(
681
- # None, # FIXME (see Dataframe bug below)
682
  visible = False,
683
  ),
684
  meta_keys: gr.Dropdown(
@@ -712,7 +710,7 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
712
  meta_string: gr.Textbox(
713
  visible = False,
714
  ),
715
- meta_array: gr.Matrix(
716
  visible = False,
717
  ),
718
  }
@@ -728,6 +726,15 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
728
  ],
729
  outputs = [
730
  meta_state,
 
 
 
 
 
 
 
 
 
731
  ] + file_change_components,
732
  show_progress = 'minimal',
733
  )
@@ -743,7 +750,7 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
743
  yield {
744
  meta_state: meta,
745
  file_meta: gr.Matrix(
746
- [['', '', '']] * 100, # FIXME: Workaround for Dataframe bug when user has selected data
747
  visible = True,
748
  ),
749
  meta_changes: gr.HighlightedText(
@@ -757,6 +764,33 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
757
  btn_download: gr.Button(
758
  visible = False,
759
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
760
  }
761
 
762
  if not repo_file:
@@ -793,12 +827,11 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
793
  m.append(human)
794
  meta.key[k] = (v.type, v.value)
795
 
796
- # FIXME
797
- # yield {
798
- # file_meta: gr.Matrix(
799
- # m,
800
- # ),
801
- # }
802
 
803
  for data, human in deferred_updates:
804
  human[:] = human_readable_metadata(meta, *data)
@@ -807,9 +840,6 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
807
 
808
  yield {
809
  meta_state: meta,
810
- file_meta: gr.Matrix(
811
- m,
812
- ),
813
  meta_keys: gr.Dropdown(
814
  sorted(meta.key.keys() | standard_metadata.keys()),
815
  value = '',
@@ -943,31 +973,30 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
943
  value = val if typ == GGUFValueType.STRING else '',
944
  visible = True if typ == GGUFValueType.STRING else False,
945
  ),
946
- meta_array: gr.Matrix(
947
  visible = True if typ == GGUFValueType.ARRAY else False,
948
  ),
949
  }
950
 
951
 
952
- # FIXME: Disabled for now due to Dataframe bug when user has selected data
953
- # @gr.on(
954
- # triggers = [
955
- # file_meta.select,
956
- # ],
957
- # inputs = [
958
- # ],
959
- # outputs = [
960
- # meta_keys,
961
- # ],
962
- # )
963
- # def select_metakey(
964
- # evt: gr.SelectData,
965
- # ):
966
- # return {
967
- # meta_keys: gr.Dropdown(
968
- # value = evt.row_value[0] if evt.selected else '',
969
- # ),
970
- # }
971
 
972
 
973
  def notify_state_change(
 
162
  visible = False,
163
  )
164
 
165
+ meta_array = gr.Textbox(
166
  None,
167
  label = "Unsupported",
 
 
168
  interactive = False,
169
  visible = False,
170
  )
 
193
  ],
194
  datatype = ["str", "str", "str"],
195
  column_widths = ["35%", "15%", "50%"],
196
+ wrap = False,
197
  interactive = False,
198
  visible = False,
199
  )
 
657
  meta_string: gr.Textbox(
658
  visible = False,
659
  ),
660
+ meta_array: gr.Textbox(
661
  visible = False,
662
  ),
663
  }
 
676
  visible = False,
677
  ),
678
  file_meta: gr.Matrix(
679
+ None,
680
  visible = False,
681
  ),
682
  meta_keys: gr.Dropdown(
 
710
  meta_string: gr.Textbox(
711
  visible = False,
712
  ),
713
+ meta_array: gr.Textbox(
714
  visible = False,
715
  ),
716
  }
 
726
  ],
727
  outputs = [
728
  meta_state,
729
+ meta_types,
730
+ btn_delete,
731
+ meta_boolean,
732
+ meta_token_select,
733
+ meta_token_type,
734
+ meta_lookup,
735
+ meta_number,
736
+ meta_string,
737
+ meta_array,
738
  ] + file_change_components,
739
  show_progress = 'minimal',
740
  )
 
750
  yield {
751
  meta_state: meta,
752
  file_meta: gr.Matrix(
753
+ None,
754
  visible = True,
755
  ),
756
  meta_changes: gr.HighlightedText(
 
764
  btn_download: gr.Button(
765
  visible = False,
766
  ),
767
+ meta_types: gr.Dropdown(
768
+ visible = False,
769
+ ),
770
+ btn_delete: gr.Button(
771
+ visible = False,
772
+ ),
773
+ meta_boolean: gr.Checkbox(
774
+ visible = False,
775
+ ),
776
+ meta_token_select: gr.Dropdown(
777
+ visible = False,
778
+ ),
779
+ meta_token_type: gr.Dropdown(
780
+ visible = False,
781
+ ),
782
+ meta_lookup: gr.Dropdown(
783
+ visible = False,
784
+ ),
785
+ meta_number: gr.Number(
786
+ visible = False,
787
+ ),
788
+ meta_string: gr.Textbox(
789
+ visible = False,
790
+ ),
791
+ meta_array: gr.Textbox(
792
+ visible = False,
793
+ ),
794
  }
795
 
796
  if not repo_file:
 
827
  m.append(human)
828
  meta.key[k] = (v.type, v.value)
829
 
830
+ yield {
831
+ file_meta: gr.Matrix(
832
+ m,
833
+ ),
834
+ }
 
835
 
836
  for data, human in deferred_updates:
837
  human[:] = human_readable_metadata(meta, *data)
 
840
 
841
  yield {
842
  meta_state: meta,
 
 
 
843
  meta_keys: gr.Dropdown(
844
  sorted(meta.key.keys() | standard_metadata.keys()),
845
  value = '',
 
973
  value = val if typ == GGUFValueType.STRING else '',
974
  visible = True if typ == GGUFValueType.STRING else False,
975
  ),
976
+ meta_array: gr.Textbox(
977
  visible = True if typ == GGUFValueType.ARRAY else False,
978
  ),
979
  }
980
 
981
 
982
+ @gr.on(
983
+ triggers = [
984
+ file_meta.select,
985
+ ],
986
+ inputs = [
987
+ ],
988
+ outputs = [
989
+ meta_keys,
990
+ ],
991
+ )
992
+ def select_metakey(
993
+ evt: gr.SelectData,
994
+ ):
995
+ return {
996
+ meta_keys: gr.Dropdown(
997
+ value = evt.row_value[0] if evt.selected else '',
998
+ ),
999
+ }
 
1000
 
1001
 
1002
  def notify_state_change(