openfree commited on
Commit
ed53868
ยท
verified ยท
1 Parent(s): 270a16a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -23
app.py CHANGED
@@ -87,26 +87,62 @@ def take_screenshot(url):
87
 
88
  def get_hardware_info(item: dict) -> tuple:
89
  """ํ•˜๋“œ์›จ์–ด ์ •๋ณด ์ถ”์ถœ"""
90
- hardware = item.get('hardware', {})
91
-
92
- # CPU ์ •๋ณด ์ฒ˜๋ฆฌ
93
- cpu_info = hardware.get('cpu', 'Standard')
94
-
95
- # GPU ์ •๋ณด ์ฒ˜๋ฆฌ
96
- gpu_info = hardware.get('gpu', {})
97
- if isinstance(gpu_info, dict):
98
- gpu_name = gpu_info.get('name', '')
99
- gpu_memory = gpu_info.get('memory', '')
100
- gpu_info = f"{gpu_name} ({gpu_memory}GB)" if gpu_name and gpu_memory else "None"
101
- elif isinstance(gpu_info, str):
102
- gpu_info = gpu_info if gpu_info else "None"
103
- else:
104
  gpu_info = "None"
105
-
106
- # SDK ์ •๋ณด ์ฒ˜๋ฆฌ
107
- sdk = item.get('sdk', 'N/A')
108
-
109
- return cpu_info, gpu_info, sdk
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  def get_card(item: dict, index: int, card_type: str = "space") -> str:
112
  """ํ†ตํ•ฉ ์นด๋“œ HTML ์ƒ์„ฑ"""
@@ -346,19 +382,26 @@ def get_card(item: dict, index: int, card_type: str = "space") -> str:
346
  </div>
347
  </div>
348
  """
349
-
350
-
351
  def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
352
  """ํŠธ๋ Œ๋”ฉ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ ธ์˜ค๊ธฐ"""
353
  url = "https://huggingface.co/api/spaces"
354
 
355
  try:
356
  progress(0, desc="Fetching spaces data...")
357
- response = requests.get(url)
 
 
 
 
 
 
358
  response.raise_for_status()
359
  spaces = response.json()
360
 
361
- # ์ƒ์œ„ 10๊ฐœ๋งŒ ์„ ํƒ (์›๋ณธ ์ˆœ์„œ ์œ ์ง€)
 
 
 
362
  top_spaces = spaces[:10]
363
 
364
  progress(0.1, desc="Creating gallery...")
 
87
 
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:
148
  """ํ†ตํ•ฉ ์นด๋“œ HTML ์ƒ์„ฑ"""
 
382
  </div>
383
  </div>
384
  """
 
 
385
  def get_trending_spaces(progress=gr.Progress()) -> Tuple[str, str]:
386
  """ํŠธ๋ Œ๋”ฉ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ ธ์˜ค๊ธฐ"""
387
  url = "https://huggingface.co/api/spaces"
388
 
389
  try:
390
  progress(0, desc="Fetching spaces data...")
391
+ # ๋” ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๋„๋ก ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€
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...")