awacke1 commited on
Commit
89cde45
·
verified ·
1 Parent(s): 44f6f5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -6,27 +6,23 @@ from huggingface_hub import HfApi, ModelCard
6
 
7
  def search_hub(query: str, search_type: str) -> pd.DataFrame:
8
  api = HfApi()
9
- data = []
10
-
11
  if search_type == "Models":
12
  results = api.list_models(search=query)
13
- data = [{"id": model.modelId, "author": model.author, "downloads": model.downloads,
14
- "link": f"https://huggingface.co/{model.modelId}"} for model in results]
15
  elif search_type == "Datasets":
16
  results = api.list_datasets(search=query)
17
- data = [{"id": dataset.id, "author": dataset.author, "downloads": dataset.downloads,
18
- "link": f"https://huggingface.co/datasets/{dataset.id}"} for dataset in results]
19
  elif search_type == "Spaces":
20
  results = api.list_spaces(search=query)
21
- data = [{"id": space.id, "author": space.author,
22
- "link": f"https://huggingface.co/spaces/{space.id}"} for space in results]
23
-
24
  return pd.DataFrame(data)
25
 
26
  def open_url(row):
27
  if row is not None and not row.empty:
28
  url = row.iloc[0]['link']
29
- return f'<a href="{url}" target="_blank">{url}</a>'
30
  else:
31
  return ""
32
 
@@ -89,7 +85,7 @@ with gr.Blocks() as demo:
89
  search_type = gr.Radio(["Models", "Datasets", "Spaces"], label="Search Type", value="Models")
90
  search_button = gr.Button("Search")
91
  results_df = gr.DataFrame(label="Search Results", wrap=True, interactive=True)
92
- url_output = gr.HTML(label="URL")
93
  metadata_output = gr.Textbox(label="Metadata", lines=10)
94
  aggregated_output = gr.JSON(label="Aggregated Content")
95
 
@@ -99,7 +95,7 @@ with gr.Blocks() as demo:
99
  return df, aggregated
100
 
101
  search_button.click(search_and_aggregate, inputs=[search_query, search_type], outputs=[results_df, aggregated_output])
102
- results_df.select(open_url, outputs=[url_output])
103
  results_df.select(load_metadata, inputs=[results_df, search_type], outputs=[metadata_output])
104
 
105
- demo.launch(debug=True)
 
6
 
7
  def search_hub(query: str, search_type: str) -> pd.DataFrame:
8
  api = HfApi()
 
 
9
  if search_type == "Models":
10
  results = api.list_models(search=query)
11
+ data = [{"id": model.modelId, "author": model.author, "downloads": model.downloads, "link": f"https://huggingface.co/{model.modelId}"} for model in results]
 
12
  elif search_type == "Datasets":
13
  results = api.list_datasets(search=query)
14
+ data = [{"id": dataset.id, "author": dataset.author, "downloads": dataset.downloads, "link": f"https://huggingface.co/datasets/{dataset.id}"} for dataset in results]
 
15
  elif search_type == "Spaces":
16
  results = api.list_spaces(search=query)
17
+ data = [{"id": space.id, "author": space.author, "link": f"https://huggingface.co/spaces/{space.id}"} for space in results]
18
+ else:
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
 
 
85
  search_type = gr.Radio(["Models", "Datasets", "Spaces"], label="Search Type", value="Models")
86
  search_button = gr.Button("Search")
87
  results_df = gr.DataFrame(label="Search Results", wrap=True, interactive=True)
88
+ web_view = gr.HTML(label="Web View")
89
  metadata_output = gr.Textbox(label="Metadata", lines=10)
90
  aggregated_output = gr.JSON(label="Aggregated Content")
91
 
 
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)