awacke1 commited on
Commit
42421e0
·
verified ·
1 Parent(s): 9646ea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,5 +1,4 @@
1
  from typing import List, Dict
2
- import httpx
3
  import gradio as gr
4
  import pandas as pd
5
  from huggingface_hub import HfApi, ModelCard
@@ -21,14 +20,14 @@ def search_hub(query: str, search_type: str) -> pd.DataFrame:
21
 
22
  def open_url(row):
23
  if row is not None and not row.empty:
24
- url = row.iloc[0]['link']
25
  return f'<iframe src="{url}" width="100%" height="600px"></iframe>'
26
  else:
27
  return ""
28
 
29
  def load_metadata(row, search_type):
30
  if row is not None and not row.empty:
31
- item_id = row.iloc[0]['id']
32
 
33
  if search_type == "Models":
34
  try:
@@ -95,7 +94,14 @@ with gr.Blocks() as demo:
95
  return df, aggregated
96
 
97
  search_button.click(search_and_aggregate, inputs=[search_query, search_type], outputs=[results_df, aggregated_output])
98
- results_df.select(open_url, outputs=[web_view])
99
- results_df.select(load_metadata, inputs=[results_df, search_type], outputs=[metadata_output])
 
 
 
 
 
 
 
100
 
101
- demo.launch(debug=True)
 
1
  from typing import List, Dict
 
2
  import gradio as gr
3
  import pandas as pd
4
  from huggingface_hub import HfApi, ModelCard
 
20
 
21
  def open_url(row):
22
  if row is not None and not row.empty:
23
+ url = row['link']
24
  return f'<iframe src="{url}" width="100%" height="600px"></iframe>'
25
  else:
26
  return ""
27
 
28
  def load_metadata(row, search_type):
29
  if row is not None and not row.empty:
30
+ item_id = row['id']
31
 
32
  if search_type == "Models":
33
  try:
 
94
  return df, aggregated
95
 
96
  search_button.click(search_and_aggregate, inputs=[search_query, search_type], outputs=[results_df, aggregated_output])
97
+
98
+ def on_select_row(row):
99
+ if row is not None:
100
+ url_content = open_url(row)
101
+ metadata_content = load_metadata(row, search_type)
102
+ return url_content, metadata_content
103
+ return "", ""
104
+
105
+ results_df.select(on_select_row, outputs=[web_view, metadata_output])
106
 
107
+ demo.launch(debug=True)