vikramvasudevan commited on
Commit
d838a4b
·
verified ·
1 Parent(s): 3485c54

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -53,6 +53,13 @@ def show_loading():
53
  return gr.update(value="⏳Fetching ...")
54
 
55
 
 
 
 
 
 
 
 
56
  # -------------------------------
57
  # Fetch & index channels
58
  # -------------------------------
@@ -103,7 +110,7 @@ def list_channels_radio():
103
  cname = val
104
  curl = key
105
  if curl:
106
- choices.append((cname, curl ))
107
  return choices
108
 
109
 
@@ -177,16 +184,21 @@ with gr.Blocks() as demo:
177
 
178
  with gr.Row():
179
  show_videos_btn = gr.Button(
180
- "Videos", size="sm", scale=0, variant="secondary"
 
 
 
 
181
  )
182
  refresh_all_btn = gr.Button(
183
- "🔄 Refresh", size="sm", scale=0, variant="huggingface"
184
  )
185
  add_channels_btn = gr.Button(
186
- "+ Add", size="sm", scale=0, variant="primary"
187
  )
 
188
  delete_channel_btn = gr.Button(
189
- "Delete", size="sm", scale=0, variant="stop", visible=False
190
  )
191
 
192
  refresh_status = gr.Markdown(label="Refresh Status", container=False)
@@ -234,7 +246,14 @@ with gr.Blocks() as demo:
234
 
235
  with gr.Row():
236
  gr.Column()
237
- ask_btn = gr.Button("Get Answer", variant="primary", scale=0)
 
 
 
 
 
 
 
238
  ask_status = gr.Markdown()
239
  gr.Column()
240
 
@@ -246,6 +265,15 @@ with gr.Blocks() as demo:
246
  clear_component, outputs=[ask_status]
247
  )
248
 
 
 
 
 
 
 
 
 
 
249
  # Show videos modal when button clicked
250
  def show_selected_channel_videos(selected_channel_name):
251
  for cname, curl in list_channels_radio():
@@ -253,6 +281,9 @@ with gr.Blocks() as demo:
253
  return fetch_channel_html(curl)
254
  return "<p>No videos found.</p>"
255
 
 
 
 
256
  show_videos_btn.click(disable_component, outputs=[show_videos_btn]).then(
257
  close_component, outputs=[my_sidebar]
258
  ).then(
 
53
  return gr.update(value="⏳Fetching ...")
54
 
55
 
56
+ def enable_if_not_none(question):
57
+ if question is None:
58
+ return disable_component()
59
+ else:
60
+ return enable_component()
61
+
62
+
63
  # -------------------------------
64
  # Fetch & index channels
65
  # -------------------------------
 
110
  cname = val
111
  curl = key
112
  if curl:
113
+ choices.append((cname, curl))
114
  return choices
115
 
116
 
 
184
 
185
  with gr.Row():
186
  show_videos_btn = gr.Button(
187
+ "🎬Videos",
188
+ size="sm",
189
+ scale=0,
190
+ variant="secondary",
191
+ interactive=False,
192
  )
193
  refresh_all_btn = gr.Button(
194
+ "🔄Refresh", size="sm", scale=0, variant="huggingface"
195
  )
196
  add_channels_btn = gr.Button(
197
+ " Add", size="sm", scale=0, variant="primary"
198
  )
199
+
200
  delete_channel_btn = gr.Button(
201
+ "🗑️ Delete", size="sm", scale=0, variant="stop", visible=False
202
  )
203
 
204
  refresh_status = gr.Markdown(label="Refresh Status", container=False)
 
246
 
247
  with gr.Row():
248
  gr.Column()
249
+ ask_btn = gr.Button(
250
+ "💡 Get Answer",
251
+ size="sm",
252
+ scale=0,
253
+ variant="primary",
254
+ interactive=False,
255
+ )
256
+
257
  ask_status = gr.Markdown()
258
  gr.Column()
259
 
 
265
  clear_component, outputs=[ask_status]
266
  )
267
 
268
+ question.change(enable_if_not_none, inputs=[question], outputs=[ask_btn])
269
+ question.submit(show_loading, outputs=[ask_status]).then(
270
+ disable_component, outputs=[ask_btn]
271
+ ).then(handle_query, inputs=[question], outputs=[answer, video_embed]).then(
272
+ enable_component, outputs=[ask_btn]
273
+ ).then(
274
+ clear_component, outputs=[ask_status]
275
+ )
276
+
277
  # Show videos modal when button clicked
278
  def show_selected_channel_videos(selected_channel_name):
279
  for cname, curl in list_channels_radio():
 
281
  return fetch_channel_html(curl)
282
  return "<p>No videos found.</p>"
283
 
284
+ channel_radio.change(
285
+ enable_if_not_none, inputs=[channel_radio], outputs=[show_videos_btn]
286
+ )
287
  show_videos_btn.click(disable_component, outputs=[show_videos_btn]).then(
288
  close_component, outputs=[my_sidebar]
289
  ).then(