awacke1 commited on
Commit
f1c52f2
·
verified ·
1 Parent(s): c5ed223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -19,21 +19,21 @@ def search_hub(query: str, search_type: str) -> pd.DataFrame:
19
  data = []
20
  return pd.DataFrame(data)
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:
35
  card = ModelCard.load(item_id)
36
- return card
37
  except Exception as e:
38
  return f"Error loading model card: {str(e)}"
39
  elif search_type == "Datasets":
@@ -95,7 +95,7 @@ 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)
 
19
  data = []
20
  return pd.DataFrame(data)
21
 
22
+ def open_url(evt: gr.SelectData, df: pd.DataFrame):
23
+ if df is not None and not df.empty and evt.index[0] < len(df):
24
+ url = df.iloc[evt.index[0]]['link']
25
  return f'<iframe src="{url}" width="100%" height="600px"></iframe>'
26
  else:
27
  return ""
28
 
29
+ def load_metadata(evt: gr.SelectData, df: pd.DataFrame, search_type: str):
30
+ if df is not None and not df.empty and evt.index[0] < len(df):
31
+ item_id = df.iloc[evt.index[0]]['id']
32
 
33
  if search_type == "Models":
34
  try:
35
  card = ModelCard.load(item_id)
36
+ return str(card)
37
  except Exception as e:
38
  return f"Error loading model card: {str(e)}"
39
  elif search_type == "Datasets":
 
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, inputs=[results_df], outputs=[web_view])
99
  results_df.select(load_metadata, inputs=[results_df, search_type], outputs=[metadata_output])
100
 
101
  demo.launch(debug=True)