openfree commited on
Commit
58eb2f8
โ€ข
1 Parent(s): ed53868

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -45
app.py CHANGED
@@ -88,60 +88,37 @@ def take_screenshot(url):
88
  def get_hardware_info(item: dict) -> tuple:
89
  """ํ•˜๋“œ์›จ์–ด ์ •๋ณด ์ถ”์ถœ"""
90
  try:
91
- # ๋””๋ฒ„๊ทธ์šฉ ์ถœ๋ ฅ
92
- print("Hardware Info:", item.get('hardware', {}))
93
-
94
- hardware = item.get('hardware', {})
95
- resources = item.get('resources', {}) # resources ํ•„๋“œ๋„ ํ™•์ธ
96
 
97
  # CPU ์ •๋ณด ์ฒ˜๋ฆฌ
98
- cpu_info = hardware.get('cpu', 'Standard')
99
 
100
- # GPU ์ •๋ณด ์ฒ˜๋ฆฌ - ์—ฌ๋Ÿฌ ๊ฐ€๋Šฅํ•œ ๊ฒฝ๋กœ ํ™•์ธ
101
  gpu_info = "None"
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- # 1. hardware.gpu์—์„œ ํ™•์ธ
104
- if 'gpu' in hardware:
105
- gpu_data = hardware['gpu']
106
- if isinstance(gpu_data, dict):
107
- gpu_name = gpu_data.get('name', '')
108
- gpu_memory = gpu_data.get('memory', '')
109
- if gpu_name or gpu_memory:
110
- gpu_info = f"{gpu_name} ({gpu_memory}GB)" if gpu_memory else gpu_name
111
- elif isinstance(gpu_data, str) and gpu_data:
112
- gpu_info = gpu_data
113
-
114
- # 2. resources.gpu์—์„œ ํ™•์ธ
115
- if gpu_info == "None" and 'gpu' in resources:
116
- gpu_data = resources['gpu']
117
- if isinstance(gpu_data, dict):
118
- gpu_name = gpu_data.get('name', '')
119
- gpu_memory = gpu_data.get('memory', '')
120
- if gpu_name or gpu_memory:
121
- gpu_info = f"{gpu_name} ({gpu_memory}GB)" if gpu_memory else gpu_name
122
- elif isinstance(gpu_data, str) and gpu_data:
123
- gpu_info = gpu_data
124
-
125
- # 3. runtime.gpu์—์„œ ํ™•์ธ
126
- runtime = item.get('runtime', {})
127
- if gpu_info == "None" and 'gpu' in runtime:
128
- gpu_data = runtime['gpu']
129
- if isinstance(gpu_data, dict):
130
- gpu_name = gpu_data.get('name', '')
131
- gpu_memory = gpu_data.get('memory', '')
132
- if gpu_name or gpu_memory:
133
- gpu_info = f"{gpu_name} ({gpu_memory}GB)" if gpu_memory else gpu_name
134
- elif isinstance(gpu_data, str) and gpu_data:
135
- gpu_info = gpu_data
136
-
137
  # SDK ์ •๋ณด ์ฒ˜๋ฆฌ
138
  sdk = item.get('sdk', 'N/A')
139
 
 
 
 
140
  return cpu_info, gpu_info, sdk
141
 
142
  except Exception as e:
143
  print(f"Error parsing hardware info: {str(e)}")
144
- print(f"Item data: {item}")
145
  return 'Standard', 'None', 'N/A'
146
 
147
  def get_card(item: dict, index: int, card_type: str = "space") -> str:
@@ -382,6 +359,7 @@ def get_card(item: dict, index: int, card_type: str = "space") -> str:
382
  </div>
383
  </div>
384
  """
 
385
  def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
386
  """ํŠธ๋ Œ๋”ฉ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ ธ์˜ค๊ธฐ"""
387
  url = "https://huggingface.co/api/spaces"
@@ -392,17 +370,24 @@ def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
392
  params = {
393
  'full': 'true',
394
  'limit': 10,
395
- 'hardware': 'true'
 
 
 
 
396
  }
397
- response = requests.get(url, params=params)
 
398
  response.raise_for_status()
399
  spaces = response.json()
400
 
401
  # ๋””๋ฒ„๊ทธ์šฉ ์ถœ๋ ฅ
402
- print("First space hardware info:", spaces[0].get('hardware', {}))
403
 
404
  # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ
405
  top_spaces = spaces[:10]
 
 
406
 
407
  progress(0.1, desc="Creating gallery...")
408
  html_content = """
 
88
  def get_hardware_info(item: dict) -> tuple:
89
  """ํ•˜๋“œ์›จ์–ด ์ •๋ณด ์ถ”์ถœ"""
90
  try:
91
+ # runtime ์ •๋ณด ํ™•์ธ
92
+ runtime = item.get('runtime', {})
 
 
 
93
 
94
  # CPU ์ •๋ณด ์ฒ˜๋ฆฌ
95
+ cpu_info = runtime.get('cpu', 'Standard')
96
 
97
+ # GPU ์ •๋ณด ์ฒ˜๋ฆฌ
98
  gpu_info = "None"
99
+ if runtime.get('accelerator') == "gpu":
100
+ gpu_type = runtime.get('gpu', {}).get('name', '')
101
+ gpu_memory = runtime.get('gpu', {}).get('memory', '')
102
+ if gpu_type:
103
+ gpu_info = f"{gpu_type}"
104
+ if gpu_memory:
105
+ gpu_info += f" ({gpu_memory}GB)"
106
+
107
+ # spaces decorator ํ™•์ธ
108
+ if '@spaces.GPU' in str(item.get('sdk_version', '')):
109
+ if gpu_info == "None":
110
+ gpu_info = "GPU Enabled"
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  # SDK ์ •๋ณด ์ฒ˜๋ฆฌ
113
  sdk = item.get('sdk', 'N/A')
114
 
115
+ print(f"Debug - Runtime Info: {runtime}") # ๋””๋ฒ„๊ทธ ์ถœ๋ ฅ
116
+ print(f"Debug - GPU Info: {gpu_info}") # ๋””๋ฒ„๊ทธ ์ถœ๋ ฅ
117
+
118
  return cpu_info, gpu_info, sdk
119
 
120
  except Exception as e:
121
  print(f"Error parsing hardware info: {str(e)}")
 
122
  return 'Standard', 'None', 'N/A'
123
 
124
  def get_card(item: dict, index: int, card_type: str = "space") -> str:
 
359
  </div>
360
  </div>
361
  """
362
+
363
  def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
364
  """ํŠธ๋ Œ๋”ฉ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ ธ์˜ค๊ธฐ"""
365
  url = "https://huggingface.co/api/spaces"
 
370
  params = {
371
  'full': 'true',
372
  'limit': 10,
373
+ 'hardware': 'true',
374
+ 'runtime': 'true' # runtime ์ •๋ณด ํฌํ•จ
375
+ }
376
+ headers = {
377
+ 'Accept': 'application/json'
378
  }
379
+
380
+ response = requests.get(url, params=params, headers=headers)
381
  response.raise_for_status()
382
  spaces = response.json()
383
 
384
  # ๋””๋ฒ„๊ทธ์šฉ ์ถœ๋ ฅ
385
+ print("First space full info:", spaces[0])
386
 
387
  # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ
388
  top_spaces = spaces[:10]
389
+
390
+
391
 
392
  progress(0.1, desc="Creating gallery...")
393
  html_content = """