davidberenstein1957 HF staff commited on
Commit
f191a3e
1 Parent(s): 5f76c1a

feat: streamline UX

Browse files
Files changed (1) hide show
  1. app.py +51 -10
app.py CHANGED
@@ -40,13 +40,16 @@ def get_columns(split: str):
40
  choices=ds_split.column_names,
41
  value=ds_split.column_names[0],
42
  label="Select a column",
 
43
  )
44
 
45
 
46
  def get_splits():
47
  global ds
48
  splits = list(ds.keys())
49
- return gr.Dropdown(choices=splits, value=splits[0], label="Select a split")
 
 
50
 
51
 
52
  def vectorize_dataset(split: str, column: str):
@@ -60,7 +63,7 @@ def vectorize_dataset(split: str, column: str):
60
  def run_query(query: str):
61
  global df
62
  vector = model.encode(query)
63
- return duckdb.sql(
64
  query=f"""
65
  SELECT *
66
  FROM df
@@ -68,6 +71,32 @@ def run_query(query: str):
68
  LIMIT 5
69
  """
70
  ).to_df()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
 
73
  with gr.Blocks() as demo:
@@ -92,24 +121,36 @@ with gr.Blocks() as demo:
92
  with gr.Row():
93
  search_out = gr.HTML(label="Search Results")
94
 
95
- with gr.Row(variant="panel"):
96
- split_dropdown = gr.Dropdown(label="Select a split")
97
- column_dropdown = gr.Dropdown(label="Select a column")
98
- with gr.Row(variant="panel"):
99
- query_input = gr.Textbox(label="Query")
 
 
 
 
100
  search_in.submit(get_iframe, inputs=search_in, outputs=search_out).then(
101
  fn=load_dataset_from_hub,
102
  inputs=search_in,
103
  show_progress=True,
 
 
 
104
  ).then(fn=get_splits, outputs=split_dropdown).then(
105
  fn=get_columns, inputs=split_dropdown, outputs=column_dropdown
106
  )
 
107
  split_dropdown.change(
108
  fn=get_columns, inputs=split_dropdown, outputs=column_dropdown
109
- ).then(fn=vectorize_dataset, inputs=[split_dropdown, column_dropdown])
110
 
111
- btn_run = gr.Button("Run")
112
- results_output = gr.Dataframe(label="Results")
 
 
 
 
113
 
114
  btn_run.click(fn=run_query, inputs=query_input, outputs=results_output)
115
  demo.launch()
 
40
  choices=ds_split.column_names,
41
  value=ds_split.column_names[0],
42
  label="Select a column",
43
+ visible=True,
44
  )
45
 
46
 
47
  def get_splits():
48
  global ds
49
  splits = list(ds.keys())
50
+ return gr.Dropdown(
51
+ choices=splits, value=splits[0], label="Select a split", visible=True
52
+ )
53
 
54
 
55
  def vectorize_dataset(split: str, column: str):
 
63
  def run_query(query: str):
64
  global df
65
  vector = model.encode(query)
66
+ df_results = duckdb.sql(
67
  query=f"""
68
  SELECT *
69
  FROM df
 
71
  LIMIT 5
72
  """
73
  ).to_df()
74
+ return gr.Dataframe(df_results, visible=True)
75
+
76
+
77
+ def hide_components():
78
+ return [
79
+ gr.Dropdown(visible=False),
80
+ gr.Dropdown(visible=False),
81
+ gr.Textbox(visible=False),
82
+ gr.Button(visible=False),
83
+ gr.Dataframe(visible=False),
84
+ ]
85
+
86
+
87
+ def partial_hide_components():
88
+ return [
89
+ gr.Textbox(visible=False),
90
+ gr.Button(visible=False),
91
+ gr.Dataframe(visible=False),
92
+ ]
93
+
94
+
95
+ def show_components():
96
+ return [
97
+ gr.Textbox(visible=True, label="Query"),
98
+ gr.Button(visible=True, value="Search"),
99
+ ]
100
 
101
 
102
  with gr.Blocks() as demo:
 
121
  with gr.Row():
122
  search_out = gr.HTML(label="Search Results")
123
 
124
+ with gr.Row():
125
+ split_dropdown = gr.Dropdown(label="Select a split", visible=False)
126
+ column_dropdown = gr.Dropdown(label="Select a column", visible=False)
127
+ with gr.Row():
128
+ query_input = gr.Textbox(label="Query", visible=False)
129
+
130
+ btn_run = gr.Button("Search", visible=False)
131
+ results_output = gr.Dataframe(label="Results", visible=False)
132
+
133
  search_in.submit(get_iframe, inputs=search_in, outputs=search_out).then(
134
  fn=load_dataset_from_hub,
135
  inputs=search_in,
136
  show_progress=True,
137
+ ).then(
138
+ fn=hide_components,
139
+ outputs=[split_dropdown, column_dropdown, query_input, btn_run, results_output],
140
  ).then(fn=get_splits, outputs=split_dropdown).then(
141
  fn=get_columns, inputs=split_dropdown, outputs=column_dropdown
142
  )
143
+
144
  split_dropdown.change(
145
  fn=get_columns, inputs=split_dropdown, outputs=column_dropdown
146
+ )
147
 
148
+ column_dropdown.change(
149
+ fn=partial_hide_components,
150
+ outputs=[query_input, btn_run, results_output],
151
+ ).then(fn=vectorize_dataset, inputs=[split_dropdown, column_dropdown]).then(
152
+ fn=show_components, outputs=[query_input, btn_run]
153
+ )
154
 
155
  btn_run.click(fn=run_query, inputs=query_input, outputs=results_output)
156
  demo.launch()