Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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(
|
| 23 |
-
if
|
| 24 |
-
url =
|
| 25 |
return f'<iframe src="{url}" width="100%" height="600px"></iframe>'
|
| 26 |
else:
|
| 27 |
return ""
|
| 28 |
|
| 29 |
-
def load_metadata(
|
| 30 |
-
if
|
| 31 |
-
item_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)
|