Update app.py
Browse files
app.py
CHANGED
@@ -23,8 +23,30 @@ def init_huggingface(token: str):
|
|
23 |
except Exception as e:
|
24 |
print(f"Error logging in: {str(e)}")
|
25 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def search_hub(query: str, search_type: str, token: str = None) -> pd.DataFrame:
|
|
|
28 |
api = HfApi(token=token)
|
29 |
if search_type == "Models":
|
30 |
results = api.list_models(search=query)
|
|
|
23 |
except Exception as e:
|
24 |
print(f"Error logging in: {str(e)}")
|
25 |
return False
|
26 |
+
|
27 |
+
# First, define format_link before it's used in search_hub
|
28 |
+
def format_link(item: Dict, number: int, search_type: str) -> str:
|
29 |
+
"""Format a link for display in the UI."""
|
30 |
+
link = item['link']
|
31 |
+
readme_link = f"{link}/blob/main/README.md"
|
32 |
+
title = f"{number}. {item['id']}"
|
33 |
+
|
34 |
+
metadata = f"Author: {item['author']}"
|
35 |
+
if 'downloads' in item:
|
36 |
+
metadata += f", Downloads: {item['downloads']}"
|
37 |
+
|
38 |
+
html = f"""
|
39 |
+
<div style="margin-bottom: 10px;">
|
40 |
+
<strong>{title}</strong><br>
|
41 |
+
<a href="{link}" target="_blank" style="color: #4a90e2; text-decoration: none;">View {search_type[:-1]}</a> |
|
42 |
+
<a href="{readme_link}" target="_blank" style="color: #4a90e2; text-decoration: none;">View README</a><br>
|
43 |
+
<small>{metadata}</small>
|
44 |
+
</div>
|
45 |
+
"""
|
46 |
+
return html
|
47 |
|
48 |
def search_hub(query: str, search_type: str, token: str = None) -> pd.DataFrame:
|
49 |
+
"""Search the Hugging Face Hub for models, datasets, or spaces."""
|
50 |
api = HfApi(token=token)
|
51 |
if search_type == "Models":
|
52 |
results = api.list_models(search=query)
|