openfree commited on
Commit
550cf29
โ€ข
1 Parent(s): 9c0a3cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -11
app.py CHANGED
@@ -336,27 +336,153 @@ def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
336
  error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
337
  return error_html, f"Error: {str(e)}"
338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  def create_interface():
340
  """Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ"""
341
- with gr.Blocks(title="Hugging Face Trending Spaces") as interface:
342
- gr.Markdown("# ๐Ÿค— Hugging Face Top 10 Trending Spaces")
343
- gr.Markdown("Shows top 10 most liked spaces on Hugging Face")
344
-
345
- with gr.Row():
346
- refresh_btn = gr.Button("Refresh Gallery", variant="primary")
347
 
348
- gallery_html = gr.HTML()
349
- status = gr.Markdown("Ready")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
- refresh_btn.click(
 
352
  fn=get_trending_spaces,
353
- outputs=[gallery_html, status],
 
 
 
 
 
 
354
  show_progress=True
355
  )
356
 
 
 
 
 
 
 
 
357
  interface.load(
358
  fn=get_trending_spaces,
359
- outputs=[gallery_html, status]
 
 
 
 
 
 
 
 
360
  )
361
 
362
  return interface
 
336
  error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
337
  return error_html, f"Error: {str(e)}"
338
 
339
+ def get_models(progress=gr.Progress()) -> Tuple[str, str]:
340
+ """์ธ๊ธฐ ๋ชจ๋ธ ๊ฐ€์ ธ์˜ค๊ธฐ"""
341
+ url = "https://huggingface.co/api/models"
342
+
343
+ try:
344
+ progress(0, desc="Fetching models data...")
345
+ response = requests.get(url)
346
+ response.raise_for_status()
347
+ models = response.json()
348
+
349
+ # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ
350
+ top_models = models[:10]
351
+
352
+ progress(0.1, desc="Creating gallery...")
353
+ html_content = """
354
+ <div style='padding: 20px; background: #f5f5f5;'>
355
+ <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
356
+ """
357
+
358
+ for idx, model in enumerate(top_models):
359
+ model_id = model.get('id', '')
360
+ author = model_id.split('/')[0]
361
+ title = model_id.split('/')[-1]
362
+ likes = format(model.get('likes', 0), ',')
363
+ downloads = format(model.get('downloads', 0), ',')
364
+ created = model.get('createdAt', '').split('T')[0]
365
+ url = f"https://huggingface.co/{model_id}"
366
+
367
+ screenshot = get_cached_screenshot(url)
368
+ html_content += get_space_card({"id": model_id, "likes": model.get('likes', 0),
369
+ "sdk": "model", "createdAt": created}, idx)
370
+
371
+ progress((0.1 + 0.9 * idx/10), desc=f"Loading model {idx+1}/10...")
372
+
373
+ html_content += "</div></div>"
374
+
375
+ progress(1.0, desc="Complete!")
376
+ return html_content, "Models gallery refresh complete!"
377
+
378
+ except Exception as e:
379
+ error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
380
+ return error_html, f"Error: {str(e)}"
381
+
382
+ def get_datasets(progress=gr.Progress()) -> Tuple[str, str]:
383
+ """์ธ๊ธฐ ๋ฐ์ดํ„ฐ์…‹ ๊ฐ€์ ธ์˜ค๊ธฐ"""
384
+ url = "https://huggingface.co/api/datasets"
385
+
386
+ try:
387
+ progress(0, desc="Fetching datasets data...")
388
+ response = requests.get(url)
389
+ response.raise_for_status()
390
+ datasets = response.json()
391
+
392
+ # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ
393
+ top_datasets = datasets[:10]
394
+
395
+ progress(0.1, desc="Creating gallery...")
396
+ html_content = """
397
+ <div style='padding: 20px; background: #f5f5f5;'>
398
+ <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
399
+ """
400
+
401
+ for idx, dataset in enumerate(top_datasets):
402
+ dataset_id = dataset.get('id', '')
403
+ author = dataset_id.split('/')[0]
404
+ title = dataset_id.split('/')[-1]
405
+ likes = format(dataset.get('likes', 0), ',')
406
+ downloads = format(dataset.get('downloads', 0), ',')
407
+ created = dataset.get('createdAt', '').split('T')[0]
408
+ url = f"https://huggingface.co/datasets/{dataset_id}"
409
+
410
+ screenshot = get_cached_screenshot(url)
411
+ html_content += get_space_card({"id": dataset_id, "likes": dataset.get('likes', 0),
412
+ "sdk": "dataset", "createdAt": created}, idx)
413
+
414
+ progress((0.1 + 0.9 * idx/10), desc=f"Loading dataset {idx+1}/10...")
415
+
416
+ html_content += "</div></div>"
417
+
418
+ progress(1.0, desc="Complete!")
419
+ return html_content, "Datasets gallery refresh complete!"
420
+
421
+ except Exception as e:
422
+ error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
423
+ return error_html, f"Error: {str(e)}"
424
+
425
  def create_interface():
426
  """Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ"""
427
+ with gr.Blocks(title="Hugging Face Trending Board") as interface:
428
+ gr.Markdown("# ๐Ÿค— Hugging Face Trending Board")
 
 
 
 
429
 
430
+ with gr.Tabs() as tabs:
431
+ # Spaces ํƒญ
432
+ with gr.Tab("๐ŸŽฏ Trending Spaces"):
433
+ gr.Markdown("Shows top 10 trending spaces on Hugging Face")
434
+ with gr.Row():
435
+ spaces_refresh_btn = gr.Button("Refresh Spaces", variant="primary")
436
+ spaces_gallery = gr.HTML()
437
+ spaces_status = gr.Markdown("Ready")
438
+
439
+ # Models ํƒญ
440
+ with gr.Tab("๐Ÿค– Trending Models"):
441
+ gr.Markdown("Shows top 10 trending models on Hugging Face")
442
+ with gr.Row():
443
+ models_refresh_btn = gr.Button("Refresh Models", variant="primary")
444
+ models_gallery = gr.HTML()
445
+ models_status = gr.Markdown("Ready")
446
+
447
+ # Datasets ํƒญ
448
+ with gr.Tab("๐Ÿ“Š Trending Datasets"):
449
+ gr.Markdown("Shows top 10 trending datasets on Hugging Face")
450
+ with gr.Row():
451
+ datasets_refresh_btn = gr.Button("Refresh Datasets", variant="primary")
452
+ datasets_gallery = gr.HTML()
453
+ datasets_status = gr.Markdown("Ready")
454
 
455
+ # Event handlers
456
+ spaces_refresh_btn.click(
457
  fn=get_trending_spaces,
458
+ outputs=[spaces_gallery, spaces_status],
459
+ show_progress=True
460
+ )
461
+
462
+ models_refresh_btn.click(
463
+ fn=get_models,
464
+ outputs=[models_gallery, models_status],
465
  show_progress=True
466
  )
467
 
468
+ datasets_refresh_btn.click(
469
+ fn=get_datasets,
470
+ outputs=[datasets_gallery, datasets_status],
471
+ show_progress=True
472
+ )
473
+
474
+ # ์ดˆ๊ธฐ ๋กœ๋“œ
475
  interface.load(
476
  fn=get_trending_spaces,
477
+ outputs=[spaces_gallery, spaces_status]
478
+ )
479
+ interface.load(
480
+ fn=get_models,
481
+ outputs=[models_gallery, models_status]
482
+ )
483
+ interface.load(
484
+ fn=get_datasets,
485
+ outputs=[datasets_gallery, datasets_status]
486
  )
487
 
488
  return interface