Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,23 +40,40 @@ class PaperManager:
|
|
| 40 |
Fetch the repositories (models, datasets, Spaces) associated with a given arxiv_id.
|
| 41 |
Returns a dictionary with counts for each type.
|
| 42 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
try:
|
|
|
|
| 44 |
response = requests.get(REPOS_API_URL_TEMPLATE.format(arxiv_id=arxiv_id))
|
| 45 |
response.raise_for_status()
|
| 46 |
data = response.json()
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
counts = {'models': 0, 'datasets': 0, 'spaces': 0}
|
| 49 |
for repo in data:
|
| 50 |
-
repo_type = repo.get('type', '').lower()
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
counts['models'] += 1
|
| 53 |
-
elif repo_type == '
|
| 54 |
counts['datasets'] += 1
|
| 55 |
-
elif repo_type == '
|
| 56 |
counts['spaces'] += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
return counts
|
| 58 |
except requests.RequestException as e:
|
| 59 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
| 60 |
return {'models': 0, 'datasets': 0, 'spaces': 0}
|
| 61 |
except Exception as e:
|
| 62 |
print(f"Unexpected error fetching repos for arxiv_id {arxiv_id}: {e}")
|
|
@@ -74,9 +91,17 @@ class PaperManager:
|
|
| 74 |
|
| 75 |
self.raw_papers = data # Store raw data
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Fetch repos counts concurrently
|
| 78 |
with ThreadPoolExecutor(max_workers=20) as executor:
|
| 79 |
-
future_to_paper = {
|
|
|
|
|
|
|
|
|
|
| 80 |
for future in as_completed(future_to_paper):
|
| 81 |
paper = future_to_paper[future]
|
| 82 |
counts = future.result()
|
|
@@ -201,11 +226,13 @@ class PaperManager:
|
|
| 201 |
def next_page(self):
|
| 202 |
if self.current_page < self.total_pages:
|
| 203 |
self.current_page += 1
|
|
|
|
| 204 |
return self.render_papers()
|
| 205 |
|
| 206 |
def prev_page(self):
|
| 207 |
if self.current_page > 1:
|
| 208 |
self.current_page -= 1
|
|
|
|
| 209 |
return self.render_papers()
|
| 210 |
|
| 211 |
paper_manager = PaperManager()
|
|
@@ -416,4 +443,4 @@ with demo:
|
|
| 416 |
outputs=[paper_list]
|
| 417 |
)
|
| 418 |
|
| 419 |
-
demo.launch()
|
|
|
|
| 40 |
Fetch the repositories (models, datasets, Spaces) associated with a given arxiv_id.
|
| 41 |
Returns a dictionary with counts for each type.
|
| 42 |
"""
|
| 43 |
+
if not arxiv_id:
|
| 44 |
+
print("Empty arxiv_id provided.")
|
| 45 |
+
return {'models': 0, 'datasets': 0, 'spaces': 0}
|
| 46 |
+
|
| 47 |
try:
|
| 48 |
+
print(f"Fetching repositories for arxiv_id: {arxiv_id}")
|
| 49 |
response = requests.get(REPOS_API_URL_TEMPLATE.format(arxiv_id=arxiv_id))
|
| 50 |
response.raise_for_status()
|
| 51 |
data = response.json()
|
| 52 |
|
| 53 |
+
# Debugging: Print the fetched data
|
| 54 |
+
print(f"Repositories data for {arxiv_id}: {data}")
|
| 55 |
+
|
| 56 |
counts = {'models': 0, 'datasets': 0, 'spaces': 0}
|
| 57 |
for repo in data:
|
| 58 |
+
repo_type = repo.get('type', '').strip().lower()
|
| 59 |
+
print(f"Repo type found: {repo_type}") # Debugging
|
| 60 |
+
|
| 61 |
+
if repo_type == 'models':
|
| 62 |
counts['models'] += 1
|
| 63 |
+
elif repo_type == 'datasets':
|
| 64 |
counts['datasets'] += 1
|
| 65 |
+
elif repo_type == 'spaces':
|
| 66 |
counts['spaces'] += 1
|
| 67 |
+
else:
|
| 68 |
+
print(f"Unknown repo type: {repo_type}") # Debugging unknown types
|
| 69 |
+
|
| 70 |
+
print(f"Counts for {arxiv_id}: {counts}") # Debugging
|
| 71 |
return counts
|
| 72 |
except requests.RequestException as e:
|
| 73 |
+
print(f"HTTP error fetching repos for arxiv_id {arxiv_id}: {e}")
|
| 74 |
+
return {'models': 0, 'datasets': 0, 'spaces': 0}
|
| 75 |
+
except ValueError as e:
|
| 76 |
+
print(f"JSON decoding error for arxiv_id {arxiv_id}: {e}")
|
| 77 |
return {'models': 0, 'datasets': 0, 'spaces': 0}
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Unexpected error fetching repos for arxiv_id {arxiv_id}: {e}")
|
|
|
|
| 91 |
|
| 92 |
self.raw_papers = data # Store raw data
|
| 93 |
|
| 94 |
+
# Debugging: Print some arxiv_ids
|
| 95 |
+
for paper in self.raw_papers[:5]:
|
| 96 |
+
arxiv_id = paper.get('paper', {}).get('arxiv_id', '')
|
| 97 |
+
print(f"Sample arxiv_id: {arxiv_id}")
|
| 98 |
+
|
| 99 |
# Fetch repos counts concurrently
|
| 100 |
with ThreadPoolExecutor(max_workers=20) as executor:
|
| 101 |
+
future_to_paper = {
|
| 102 |
+
executor.submit(self.fetch_repos_counts, paper.get('paper', {}).get('arxiv_id', '')): paper
|
| 103 |
+
for paper in self.raw_papers
|
| 104 |
+
}
|
| 105 |
for future in as_completed(future_to_paper):
|
| 106 |
paper = future_to_paper[future]
|
| 107 |
counts = future.result()
|
|
|
|
| 226 |
def next_page(self):
|
| 227 |
if self.current_page < self.total_pages:
|
| 228 |
self.current_page += 1
|
| 229 |
+
print(f"Navigated to page {self.current_page}") # Debug
|
| 230 |
return self.render_papers()
|
| 231 |
|
| 232 |
def prev_page(self):
|
| 233 |
if self.current_page > 1:
|
| 234 |
self.current_page -= 1
|
| 235 |
+
print(f"Navigated to page {self.current_page}") # Debug
|
| 236 |
return self.render_papers()
|
| 237 |
|
| 238 |
paper_manager = PaperManager()
|
|
|
|
| 443 |
outputs=[paper_list]
|
| 444 |
)
|
| 445 |
|
| 446 |
+
demo.launch()
|