Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,33 +6,29 @@ 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 |
-
|
| 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['link']
|
| 29 |
return f'<iframe src="{url}" width="100%" height="600px"></iframe>'
|
| 30 |
else:
|
| 31 |
return ""
|
| 32 |
|
| 33 |
def load_metadata(row, search_type):
|
| 34 |
if row is not None and not row.empty:
|
| 35 |
-
item_id = row['id']
|
| 36 |
|
| 37 |
if search_type == "Models":
|
| 38 |
try:
|
|
@@ -89,21 +85,17 @@ 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 |
-
|
| 93 |
metadata_output = gr.Textbox(label="Metadata", lines=10)
|
| 94 |
aggregated_output = gr.JSON(label="Aggregated Content")
|
| 95 |
-
iframe_output = gr.HTML(label="Web Page")
|
| 96 |
|
| 97 |
def search_and_aggregate(query, search_type):
|
| 98 |
df = search_hub(query, search_type)
|
| 99 |
aggregated = SwarmyTime(df.to_dict('records'))
|
| 100 |
return df, aggregated
|
| 101 |
|
| 102 |
-
def display_iframe(row):
|
| 103 |
-
return open_url(row)
|
| 104 |
-
|
| 105 |
search_button.click(search_and_aggregate, inputs=[search_query, search_type], outputs=[results_df, aggregated_output])
|
| 106 |
-
results_df.select(
|
| 107 |
results_df.select(load_metadata, inputs=[results_df, search_type], outputs=[metadata_output])
|
| 108 |
|
| 109 |
-
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 |
|
| 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:
|
|
|
|
| 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 |
|
| 92 |
def search_and_aggregate(query, search_type):
|
| 93 |
df = search_hub(query, search_type)
|
| 94 |
aggregated = SwarmyTime(df.to_dict('records'))
|
| 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)
|