Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,7 @@ def init_huggingface(token: str):
|
|
| 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"
|
|
@@ -45,6 +43,40 @@ def format_link(item: Dict, number: int, search_type: str) -> str:
|
|
| 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)
|
|
@@ -176,7 +208,7 @@ def create_repo_zip(data: List[Dict], search_type: str, token: str) -> tuple[str
|
|
| 176 |
|
| 177 |
return download_link, f"Successfully downloaded {len(successful_downloads)} repositories"
|
| 178 |
|
| 179 |
-
|
| 180 |
|
| 181 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 182 |
gr.Markdown("""
|
|
|
|
| 23 |
except Exception as e:
|
| 24 |
print(f"Error logging in: {str(e)}")
|
| 25 |
return False
|
| 26 |
+
def format_link(item: Dict, number: int, search_type: str) -> str:
|
|
|
|
|
|
|
| 27 |
"""Format a link for display in the UI."""
|
| 28 |
link = item['link']
|
| 29 |
readme_link = f"{link}/blob/main/README.md"
|
|
|
|
| 43 |
"""
|
| 44 |
return html
|
| 45 |
|
| 46 |
+
def display_results(df: pd.DataFrame):
|
| 47 |
+
"""Display search results in HTML format."""
|
| 48 |
+
if df is not None and not df.empty:
|
| 49 |
+
html = "<div style='max-height: 400px; overflow-y: auto;'>"
|
| 50 |
+
for _, row in df.iterrows():
|
| 51 |
+
html += row['formatted_link']
|
| 52 |
+
html += "</div>"
|
| 53 |
+
return html
|
| 54 |
+
else:
|
| 55 |
+
return "<p>No results found.</p>"
|
| 56 |
+
|
| 57 |
+
def SwarmyTime(data: List[Dict]) -> Dict:
|
| 58 |
+
"""Aggregates all content from the given data."""
|
| 59 |
+
aggregated = {
|
| 60 |
+
"total_items": len(data),
|
| 61 |
+
"unique_authors": set(),
|
| 62 |
+
"total_downloads": 0,
|
| 63 |
+
"item_types": {"Models": 0, "Datasets": 0, "Spaces": 0}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
for item in data:
|
| 67 |
+
aggregated["unique_authors"].add(item.get("author", "Unknown"))
|
| 68 |
+
aggregated["total_downloads"] += item.get("downloads", 0)
|
| 69 |
+
|
| 70 |
+
if "modelId" in item:
|
| 71 |
+
aggregated["item_types"]["Models"] += 1
|
| 72 |
+
elif "dataset" in item.get("id", ""):
|
| 73 |
+
aggregated["item_types"]["Datasets"] += 1
|
| 74 |
+
else:
|
| 75 |
+
aggregated["item_types"]["Spaces"] += 1
|
| 76 |
+
|
| 77 |
+
aggregated["unique_authors"] = len(aggregated["unique_authors"])
|
| 78 |
+
return aggregated
|
| 79 |
+
|
| 80 |
def search_hub(query: str, search_type: str, token: str = None) -> pd.DataFrame:
|
| 81 |
"""Search the Hugging Face Hub for models, datasets, or spaces."""
|
| 82 |
api = HfApi(token=token)
|
|
|
|
| 208 |
|
| 209 |
return download_link, f"Successfully downloaded {len(successful_downloads)} repositories"
|
| 210 |
|
| 211 |
+
|
| 212 |
|
| 213 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 214 |
gr.Markdown("""
|