refactor app (#2)
Browse files- refactor app (c2a65c26397f2d575d62a80791a4135603c1b096)
app.py
CHANGED
@@ -16,8 +16,12 @@ README_URL_TEMPLATE = "https://huggingface.co/datasets/{}/raw/main/README.md"
|
|
16 |
|
17 |
async def fetch_similar_datasets(dataset_id: str, limit: int = 10) -> List[Dict]:
|
18 |
async with httpx.AsyncClient() as client:
|
19 |
-
response = await client.get(f"{API_URL}?dataset_id={dataset_id}&n={limit}")
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
async def fetch_dataset_card(dataset_id: str) -> str:
|
@@ -106,6 +110,9 @@ def format_results(
|
|
106 |
async def search_similar_datasets(dataset_id: str, limit: int = 10):
|
107 |
results = await fetch_similar_datasets(dataset_id, limit)
|
108 |
|
|
|
|
|
|
|
109 |
# Fetch dataset cards and info concurrently
|
110 |
dataset_cards = await asyncio.gather(
|
111 |
*[fetch_dataset_card(result["dataset_id"]) for result in results]
|
|
|
16 |
|
17 |
async def fetch_similar_datasets(dataset_id: str, limit: int = 10) -> List[Dict]:
|
18 |
async with httpx.AsyncClient() as client:
|
19 |
+
response = await client.get(f"{API_URL}?dataset_id={dataset_id}&n={limit + 1}")
|
20 |
+
if response.status_code == 200:
|
21 |
+
results = response.json()["results"]
|
22 |
+
# Remove the input dataset from the results
|
23 |
+
return [r for r in results if r["dataset_id"] != dataset_id][:limit]
|
24 |
+
return []
|
25 |
|
26 |
|
27 |
async def fetch_dataset_card(dataset_id: str) -> str:
|
|
|
110 |
async def search_similar_datasets(dataset_id: str, limit: int = 10):
|
111 |
results = await fetch_similar_datasets(dataset_id, limit)
|
112 |
|
113 |
+
if not results:
|
114 |
+
return "No similar datasets found."
|
115 |
+
|
116 |
# Fetch dataset cards and info concurrently
|
117 |
dataset_cards = await asyncio.gather(
|
118 |
*[fetch_dataset_card(result["dataset_id"]) for result in results]
|