Spaces:
Sleeping
Sleeping
Update app.py
Browse files123454567108910111213143 unmodified lines181920202121222324254 unmodified lines303132323333343535363637383940414241424344454647444546474850515253495051525354565755565758606162636465666768697071727359606175767778798081828384626386878889909192939464656667686970717273747576777879968081829910083841021031041051068510810986878889112909192115116117939495961201219798991001241011021261031041051301061071081341091361371101391401111421431121131148 unmodified lines1231241251581591601611621631641651661671681691701711721261271281291301311761321331341791801351361371821381841391861871881401411421431441901911921931941951451461471481491501971981991511521531541551561571581591601611621631641652011661671681692051701711721732091741751761772131781791801811821831842171851862192201871882221892242252261901911921931942291951962312322332341971981992002012022032042052372062072392402082092102112442122132142152162172182192202522212222542232242572252262272282 unmodified lines2312322332662342352682362372381 unmodified line2402412422762432442452462472482832492502512522882892902912922932942532542552563 unmodified lines2602612623043053063073083093102632642652663 unmodified lines2702712723202733223233242742752762773282783303313322792803342813363373383392822833413423433443453463473483493503513523532842852862873553563573583593603613622882893643652902913673683692922933712943733743753763772952963792973813823832982993853863003883893903013023923033943953963973983994004014024034044054064073043053063074094104114124134144153083093104174183113123134204214224234244253143153164274284293173184313194334344354364374384394404413203213223234434444454464474484494504514524534544554563243253263273284584593293304613314634644654664674683323333343354713363373384753394774783403414804813424834844854863433443454883464904914924934943473483494963503513523533543555033565055063573585083595105115125135143603613623635173645195205215223653665243675265275285295305315325335343683693703715365375385395405413723733745433755455465475483763775505515525535545553783795575585595605615625635643803815663823835685695705715725735745755765775785795803843853863873883895825835845855865873903913923935903943953965943975965975985996006016026036043983994004016066076086094024036116124046146156166176186196206214054064074086236246256266276286296306316326336346356364094104114124136386396404144154166434176456466476486496504184194206526534216556566576586594224236614246636646656666676686696706716724254264274286744296766774304316794326816824334346844356866876886894364376916924386946956966976986997007017027034394404414427067077087097104434447127137147157164454464474484497204507227237244514527264537287297307314544557337344567367374574587394597417427434604614627464637487497504644657524667547557567577587597607617624674684694704714727664737687697707717727737744744754767764774784797804807827834814827857864837887897907917927937947954844854867977984874888004898028034904918054928078088098108118128138148158164934944954964978194988218228238248258268278288298308318324995005018348358368375025035048408418428438445055065078478488498508518528535085095105118568578588598608618628635125135145155168668678688698708718725175185195208758765215225238798808818828838845245255268878888895275288915298938948958968978988999005305315325335348 unmodified lines54354454591554654791854854955092292355155255355492892955555655716 unmodified lines5745755769525775785791 unmodified line5815825839605849625855869659665875885895905915929735935945955969789799805975985999836009856016026036045 unmodified lines6106116129976136146154 unmodified lines62062162210086236246256263 unmodified lines630631632101863363463563663710231024638639102610271028102910301031640641642643644103510366456461038647648649650651652104565365465565665710511052658105410556596606616621057663664105910606656666676686696706713 unmodified lines675676677107067867910721073680681682683684685108010816866876884 unmodified lines69369469510921093696697109669869970011 unmodified lines712713714111471571671771811197197207211 unmodified line72372472511277261129113072772872973011337317327331137734735736114073773811427397407417425 unmodified lines7487497501154115511561157115811597517527537547557567577581166116711681169759760761117211731174117576276376411787657661180118111827677687697701 unmodified line7727737741190119177577677777877911961197119811997807817827837847857 unmodified lines7937947951213121479679779879914 unmodified lines8148158161235817818819123912408208218228238241246124712488258268278288291253125412551256125783083183283383412591260835836126212638378388391265126612678408418428431271127284484584612768478481278127984985085185285385412848558561287857858129085986086112948628638648655 unmodified lines87187287387487513078768778781311879880131413158818828838843 unmodified lines888889890132513268918921328132913301331133289389489513351336896897898134089990013431344901902134790390490513509069079089 unmodified lines918919920136692192292313709249259261 unmodified line92892993013789311380932933934935936138693793813899399409412 unmodified lines9449459461398947948949950951952140514069539549551 unmodified line9579589591414960961962141714189639649659669677 unmodified lines97597697714329789799809812 unmodified lines98498598614419879889896 unmodified lines996997998145499914561000100110021003100410051463146414651006146710071008146910091010101110 unmodified lines10221023102414861487148814891490149114921493102510261496149710271028102910303 unmodified lines1034103510361507150810371038103910401 unmodified line1042104310441516104510461047152010481049105015241051105210533 unmodified lines10571058105915341060106110622 unmodified lines106510661067154310681069107012 unmodified lines10831084108515621086108710881 unmodified line10901091109215701571109310941095109610974 unmodified lines110211031104158211051106110711083 unmodified lines11121113111415921115111611173 unmodified lines11211122112316021124160411251126112711281129113016111131113211338 unmodified lines114211431144162611451146114711481149163211501151115211533 unmodified lines115711581159164211601161116215 unmodified lines117811791180166411811182118311 unmodified lines119511961197168211981199120012011202from flask import Flask, render_template, request, jsonifyimport requestsimport osimport timeimport randomfrom collections import Counter
app = Flask(__name__)
# Generate dummy spaces in case of error# --------------------- ์ ์ญ ์บ์ ---------------------SPACE_CACHE = [] # ์๋ฒ ์์ ์ ํ ๋ฒ๋ง ๋ก๋ฉ๋ ์คํ์ด์ค ๋ชฉ๋ก์ ์ ์ฅ
# --------------------- ๋๋ฏธ ๋ฐ์ดํฐ ์์ฑ ํจ์ ---------------------def generate_dummy_spaces(count): """ API ํธ์ถ ์คํจ ์ ์์์ฉ ๋๋ฏธ ์คํ์ด์ค ์์ฑ3 unmodified lines spaces.append({ 'id': f'dummy/space-{i}', 'owner': 'dummy', 'title': f'Example Space {i+1}', 'description': 'Dummy space for fallback', 'title': f'Dummy Space {i+1}', 'description': 'This is a fallback dummy space.', 'likes': 100 - i, 'createdAt': '2023-01-01T00:00:00.000Z', 'hardware': 'cpu',4 unmodified lines }) return spaces
# Function to fetch Zero-GPU (CPU-based) Spaces from Huggingface with paginationdef fetch_trending_spaces(offset=0, limit=24):# --------------------- ์๋ฒ ์์ ์ ํ ๋ฒ๋ง ํธ์ถํ์ฌ CACHE ์ฑ์ฐ๊ธฐ ---------------------def fetch_zero_gpu_spaces_once(): """ hardware=cpu ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ์ฌ GPU๊ฐ ์๋(=CPU ์ ์ฉ) ์คํ์ด์ค๋ง ํํฐ๋ง Hugging Face API์์ hardware=cpu ์คํ์ด์ค ๋ชฉ๋ก์ ๊ฐ์ ธ์ด (limit์ ์๊ฒ ์ค์ ) """ try: url = "https://huggingface.co/api/spaces" params = { "limit": 1000, # ๋ ๋ง์ด ๊ฐ์ ธ์ค๊ธฐ "hardware": "cpu" # <-- Zero GPU(=CPU) ํํฐ ์ ์ฉ "limit": 500, # limit์ ์๊ฒ ํ์ฌ ๋น ๋ฅธ ์๋ต ์ ๋ "hardware": "cpu" } response = requests.get(url, params=params, timeout=30)
if response.status_code == 200: spaces = response.json() resp = requests.get(url, params=params, timeout=30) if resp.status_code == 200: raw_spaces = resp.json()
# owner๋ id๊ฐ 'None'์ธ ๊ฒฝ์ฐ ์ ์ธ filtered_spaces = [ space for space in spaces if space.get('owner') != 'None' and space.get('id', '').split('/', 1)[0] != 'None' filtered = [ sp for sp in raw_spaces if sp.get('owner') != 'None' and sp.get('id', '').split('/', 1)[0] != 'None' ]
# ์ ์ฒด ๋ชฉ๋ก์ ๋ํด "๊ธ๋ก๋ฒ ๋ญํฌ"๋ฅผ ๋งค๊ธด๋ค (1๋ถํฐ ์์) for i, sp in enumerate(filtered_spaces): # ๊ธ๋ก๋ฒ ๋ญํฌ ๋ถ์ฌ for i, sp in enumerate(filtered): sp['global_rank'] = i + 1
# Slice according to requested offset and limit start = min(offset, len(filtered_spaces)) end = min(offset + limit, len(filtered_spaces))
print(f"[fetch_trending_spaces] CPU๊ธฐ๋ฐ ์คํ์ด์ค ์ด {len(filtered_spaces)}๊ฐ, " f"์์ฒญ ๊ตฌ๊ฐ {start}~{end-1} ๋ฐํ")
return { 'spaces': filtered_spaces[start:end], 'total': len(filtered_spaces), 'offset': offset, 'limit': limit, 'all_spaces': filtered_spaces # ํต๊ณ ์ฐ์ถ์ฉ } print(f"[fetch_zero_gpu_spaces_once] ์ฑ๊ณต์ ์ผ๋ก {len(filtered)}๊ฐ ๋ก๋") return filtered else: print(f"Error fetching spaces: {response.status_code}") # ์คํจ ์ ๋๋ฏธ ๋ฐ์ดํฐ ์์ฑ return { 'spaces': generate_dummy_spaces(limit), 'total': 200, 'offset': offset, 'limit': limit, 'all_spaces': generate_dummy_spaces(500) }
print(f"[fetch_zero_gpu_spaces_once] API ์๋ฌ: {resp.status_code}") except Exception as e: print(f"Exception when fetching spaces: {e}") # ์คํจ ์ ๋๋ฏธ ๋ฐ์ดํฐ ์์ฑ return { 'spaces': generate_dummy_spaces(limit), 'total': 200, 'offset': offset, 'limit': limit, 'all_spaces': generate_dummy_spaces(500) } print(f"[fetch_zero_gpu_spaces_once] ์์ธ ๋ฐ์: {e}")
# ์คํจ ์ ๋๋ฏธ ๋ฐ์ดํฐ ๋ฆฌํด print("[fetch_zero_gpu_spaces_once] ์คํจ โ ๋๋ฏธ ๋ฐ์ดํฐ ์ฌ์ฉ") return generate_dummy_spaces(100)
@app.before_first_requestdef load_cache(): """ Flask๊ฐ ์ฒซ ์์ฒญ์ ๋ฐ๊ธฐ ์ (์๋ฒ ์์ ์งํ) ํ ๋ฒ๋ง ์คํ. ์ ์ญ ๋ณ์ SPACE_CACHE์ CPU ์ ์ฉ ์คํ์ด์ค ์ ๋ณด๋ฅผ ๋ก๋ฉํ๋ค. """ global SPACE_CACHE SPACE_CACHE = fetch_zero_gpu_spaces_once() print(f"[load_cache] Loaded {len(SPACE_CACHE)} CPU-based Spaces into cache.")
# Transform Huggingface URL to direct space URL# --------------------- URL ๋ณํ ํจ์ ---------------------def transform_url(owner, name): """ Hugging Face Space -> ์๋ธ๋๋ฉ์ธ ์ ๊ทผ URL ์) huggingface.co/spaces/owner/spaceName -> owner-spacename.hf.space huggingface.co/spaces/owner/spaceName -> owner-spacename.hf.space """ # 1. Replace '.' with '-' name = name.replace('.', '-') # 2. Replace '_' with '-' name = name.replace('_', '-') # 3. Convert to lowercase owner = owner.lower() name = name.lower()
# '.'๋ '_' ๋ฑ์ '-'๋ก ๋ณํ name = name.replace('.', '-').replace('_', '-').lower() return f"https://{owner}-{name}.hf.space"
# Get space details# --------------------- space_details ์์ฑ ํจ์ ---------------------def get_space_details(space_data, index, offset): """ - description, avatar_url, author_name ๋ฑ ์ถ๊ฐ ํ๋๋ฅผ ์ถ์ถ - rank๋ ํ์ฌ ํ์ด์ง ๋ด offset ๊ธฐ๋ฐ์ผ๋ก ๊ณ์ฐ (๋จ, Top 500 ๊ณ์ฐ์ global_rank ์ฌ์ฉ) ์คํ์ด์ค์ ์์ธ ์ ๋ณด๋ฅผ ์ถ์ถํ๊ณ , ํ์ด์ง offset+index์ ๋ฐ๋ผ ์์(rank)๋ฅผ ๋ถ์ฌ """ try: space_id = space_data.get('id', '') if '/' in space_data.get('id', ''): owner, name = space_data.get('id', '').split('/', 1) if '/' in space_id: owner, name = space_id.split('/', 1) else: owner = space_data.get('owner', '') name = space_data.get('id', '') name = space_id
# Ignore if contains None if owner == 'None' or name == 'None': return None
# Construct URLs original_url = f"https://huggingface.co/spaces/{owner}/{name}" embed_url = transform_url(owner, name)
# Likes count likes_count = space_data.get('likes', 0)
# Title title = space_data.get('title') or name
# Description short_desc = space_data.get('description', '')
# User info (avatar, name) user_info = space_data.get('user', {}) avatar_url = user_info.get('avatar_url', '') author_name = user_info.get('name') or owner8 unmodified lines 'description': short_desc, 'avatar_url': avatar_url, 'author_name': author_name, 'rank': offset + index + 1 # ํ์ฌ ํ์ด์ง์์์ ํ์์ฉ ๋ญํฌ } except Exception as e: print(f"Error processing space data: {e}") # Return basic object even if error occurs return { 'url': 'https://huggingface.co/spaces', 'embedUrl': 'https://huggingface.co/spaces', 'title': 'Error Loading Space', 'owner': 'huggingface', 'name': 'error', 'likes_count': 0, 'description': '', 'avatar_url': '', 'author_name': 'huggingface', 'rank': offset + index + 1 } except Exception as e: print(f"[get_space_details] ์์ธ ๋ฐ์: {e}") return None
# Get owner statistics from all spaces# --------------------- owner ํต๊ณ ํจ์ ---------------------def get_owner_stats(all_spaces): """ ์์ 500์(global_rank <= 500) ์ด๋ด์ ๋ฐฐ์น๋ ์คํ์ด์ค๋ค์ owner๋ฅผ ์ถ์ถํด, ๊ฐ owner๊ฐ ๋ช ๋ฒ ๋ฑ์ฅํ๋์ง ์ผ ๋ค ์์ 30๋ช
๋ง ๋ฐํ ์์ 500(global_rank <= 500)์ ์๋ ์คํ์ด์ค๋ค์ owner๋ฅผ ์ถ์ถ, ๊ฐ owner๋ณ ๋ฑ์ฅ ํ์๋ฅผ ๊ตฌํ ๋ค ์์ 30์ธ๋ง ๋ฐํ """ # Top 500 top_500 = [s for s in all_spaces if s.get('global_rank', 999999) <= 500]
owners = [] for space in top_500: if '/' in space.get('id', ''): owner, _ = space.get('id', '').split('/', 1) for sp in top_500: sp_id = sp.get('id', '') if '/' in sp_id: o, _ = sp_id.split('/', 1) else: owner = space.get('owner', '') if owner and owner != 'None': owners.append(owner)
# Count occurrences of each owner in top 500 owner_counts = Counter(owners) o = sp.get('owner', '') if o and o != 'None': owners.append(o) counts = Counter(owners) return counts.most_common(30)
# Get top 30 owners by count top_owners = owner_counts.most_common(30) return top_owners# --------------------- ์บ์์ ์๋ ์คํ์ด์ค์์ ํ์ด์ง๋ค์ด์
์ฒ๋ฆฌ ---------------------def fetch_trending_spaces(offset=0, limit=24): global SPACE_CACHE total = len(SPACE_CACHE) start = min(offset, total) end = min(offset + limit, total) sliced = SPACE_CACHE[start:end] return { 'spaces': sliced, 'total': total, 'offset': offset, 'limit': limit, 'all_spaces': SPACE_CACHE }
# Homepage route# --------------------- ๋ผ์ฐํธ: ๋ฉ์ธ ํ์ด์ง ---------------------@app.route('/')def home(): """ index.html ํ
ํ๋ฆฟ ๋ ๋๋ง (๋ฉ์ธ ํ์ด์ง) index.html ํ
ํ๋ฆฟ์ ๋ ๋๋ง """ return render_template('index.html')
# Zero-GPU spaces API# --------------------- ๋ผ์ฐํธ: Zero-GPU ์คํ์ด์ค API ---------------------@app.route('/api/trending-spaces', methods=['GET'])def trending_spaces(): """ hardware=cpu ์คํ์ด์ค ๋ชฉ๋ก์ ๋ถ๋ฌ์ ๊ฒ์, ํ์ด์ง, ํต๊ณ ๋ฑ์ ์ ์ฉ - GET ํ๋ผ๋ฏธํฐ search, offset, limit ์ฒ๋ฆฌ - ์บ์๋ ์คํ์ด์ค ๋ชฉ๋ก์์ ํ์ด์ง๋ค์ด์
- ๊ฒ์์ด ๊ฒ์ - ํต๊ณ(owner) ๊ณ์ฐ """ search_query = request.args.get('search', '').lower() offset = int(request.args.get('offset', 0)) limit = int(request.args.get('limit', 24)) # Default changed to 24 limit = int(request.args.get('limit', 24))
# Fetch zero-gpu (cpu) spaces spaces_data = fetch_trending_spaces(offset, limit) data = fetch_trending_spaces(offset, limit)
# Process and filter spaces results = [] for index, space_data in enumerate(spaces_data['spaces']): space_info = get_space_details(space_data, index, offset) if not space_info: for idx, sp in enumerate(data['spaces']): info = get_space_details(sp, idx, offset) if not info: continue
# Apply search filter if needed # ๊ฒ์์ด ํํฐ if search_query: if (search_query not in space_info['title'].lower() and search_query not in space_info['owner'].lower() and search_query not in space_info['url'].lower() and search_query not in space_info['description'].lower()): text_block = " ".join([ info['title'].lower(), info['owner'].lower(), info['url'].lower(), info['description'].lower() ]) if search_query not in text_block: continue
results.append(space_info) results.append(info)
# Get owner statistics (Top 500 โ Top 30) top_owners = get_owner_stats(spaces_data.get('all_spaces', [])) top_owners = get_owner_stats(data['all_spaces'])
return jsonify({ 'spaces': results, 'total': spaces_data['total'], 'total': data['total'], 'offset': offset, 'limit': limit, 'top_owners': top_owners })
# --------------------- ์๋ฒ ์คํ ---------------------if __name__ == '__main__': """ ์๋ฒ ๊ตฌ๋ ์, templates/index.html ํ์ผ์ ์์ฑ ํ Flask ์คํ ์คํ ์ templates/index.html ํ์ผ์ ์๋ ์์ฑ ํ Flask ์๋ฒ ์์ """ # Create templates folder if not exists os.makedirs('templates', exist_ok=True)
# index.html ์ ์ฒด๋ฅผ ์๋ก ์์ฑ # index.html ์์ ํ
ํ๋ฆฟ (์๋ณธ ์ง๋ฌธ์ ๋ด์ฉ์ ํ ๋๋ก ์์ฑ) with open('templates/index.html', 'w', encoding='utf-8') as f: f.write('''<!DOCTYPE html><html lang="en">2 unmodified lines <title>Huggingface Zero-GPU Spaces</title> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <style> /* Google Fonts & Base Styling */ /* (์ง๋ฌธ ๋ณธ๋ฌธ์ ์ฃผ์ด์ง CSS ์ ๋ถ ์ฝ์
) */ @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;500;600;700&display=swap'); :root { --pastel-pink: #FFD6E0; --pastel-blue: #C5E8FF;1 unmodified line --pastel-yellow: #FFF2CC; --pastel-green: #C7F5D9; --pastel-orange: #FFE0C3; --mac-window-bg: rgba(250, 250, 250, 0.85); --mac-toolbar: #F5F5F7; --mac-border: #E2E2E2; --mac-button-red: #FF5F56; --mac-button-yellow: #FFBD2E; --mac-button-green: #27C93F; --text-primary: #333; --text-secondary: #666; --box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); } * { margin: 0; padding: 0; box-sizing: border-box; } * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; line-height: 1.6;3 unmodified lines min-height: 100vh; padding: 2rem; } .container { max-width: 1600px; margin: 0 auto; } /* Mac OS Window Styling */ .container { max-width: 1600px; margin: 0 auto; } .mac-window { background-color: var(--mac-window-bg); border-radius: 10px;3 unmodified lines margin-bottom: 2rem; border: 1px solid var(--mac-border); } .mac-toolbar { display: flex; align-items: center; padding: 10px 15px; display: flex; align-items: center; padding: 10px 15px; background-color: var(--mac-toolbar); border-bottom: 1px solid var(--mac-border); } .mac-buttons { display: flex; gap: 8px; margin-right: 15px; display: flex; gap: 8px; margin-right: 15px; } .mac-button { width: 12px; height: 12px; border-radius: 50%; cursor: default; width: 12px; height: 12px; border-radius: 50%; cursor: default; } .mac-close { background-color: var(--mac-button-red); } .mac-minimize { background-color: var(--mac-button-yellow); } .mac-maximize { background-color: var(--mac-button-green); } .mac-close { background-color: var(--mac-button-red); } .mac-minimize { background-color: var(--mac-button-yellow); } .mac-maximize { background-color: var(--mac-button-green); } .mac-title { flex-grow: 1; text-align: center; font-size: 0.9rem; color: var(--text-secondary); } .mac-content { padding: 20px; flex-grow: 1; text-align: center; font-size: 0.9rem; color: var(--text-secondary); } /* Header Styling */ .mac-content { padding: 20px; } .header { text-align: center; margin-bottom: 1.5rem; position: relative; text-align: center; margin-bottom: 1.5rem; position: relative; } .header h1 { font-size: 2.2rem; font-weight: 700; margin: 0; color: #2d3748; letter-spacing: -0.5px; font-size: 2.2rem; font-weight: 700; margin: 0; color: #2d3748; letter-spacing: -0.5px; } .header p { color: var(--text-secondary); margin-top: 0.5rem; font-size: 1.1rem; color: var(--text-secondary); margin-top: 0.5rem; font-size: 1.1rem; } /* Tabs Styling */ .tab-nav { display: flex; justify-content: center; margin-bottom: 1.5rem; display: flex; justify-content: center; margin-bottom: 1.5rem; } .tab-button { border: none; background-color: #edf2f7; color: var(--text-primary); padding: 10px 20px; margin: 0 5px; cursor: pointer; border-radius: 5px; font-size: 1rem; font-weight: 600; } .tab-button.active { background-color: var(--pastel-purple); color: #fff; border: none; background-color: #edf2f7; color: var(--text-primary); padding: 10px 20px; margin: 0 5px; cursor: pointer; border-radius: 5px; font-size: 1rem; font-weight: 600; } .tab-content { display: none; } .tab-content.active { display: block; .tab-button.active { background-color: var(--pastel-purple); color: #fff; } /* Controls Styling */ .tab-content { display: none; } .tab-content.active { display: block; } .search-bar { display: flex; align-items: center; margin-bottom: 1.5rem; background-color: white; border-radius: 30px; padding: 5px; display: flex; align-items: center; margin-bottom: 1.5rem; background-color: white; border-radius: 30px; padding: 5px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); max-width: 600px; margin-left: auto; margin-right: auto; max-width: 600px; margin-left: auto; margin-right: auto; } .search-bar input { flex-grow: 1; border: none; padding: 12px 20px; font-size: 1rem; outline: none; background: transparent; border-radius: 30px; } flex-grow: 1; border: none; padding: 12px 20px; font-size: 1rem; outline: none; background: transparent; border-radius: 30px; } .search-bar .refresh-btn { background-color: var(--pastel-green); color: #1a202c; border: none; border-radius: 30px; padding: 10px 20px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 8px; } background-color: var(--pastel-green); color: #1a202c; border: none; border-radius: 30px; padding: 10px 20px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 8px; } .search-bar .refresh-btn:hover { background-color: #9ee7c0; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); background-color: #9ee7c0; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); } .refresh-icon { display: inline-block; width: 16px; height: 16px; border: 2px solid #1a202c; border-top-color: transparent; border-radius: 50%; display: inline-block; width: 16px; height: 16px; border: 2px solid #1a202c; border-top-color: transparent; border-radius: 50%; animation: none; } .refreshing .refresh-icon { animation: spin 1s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } /* Grid Styling */ .grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; } .grid-item { height: 500px; position: relative; overflow: hidden; transition: all 0.3s ease; border-radius: 15px; height: 500px; position: relative; overflow: hidden; transition: all 0.3s ease; border-radius: 15px; } .grid-item:nth-child(6n+1) { background-color: var(--pastel-pink); } .grid-item:nth-child(6n+2) { background-color: var(--pastel-blue); } .grid-item:nth-child(6n+3) { background-color: var(--pastel-purple); } .grid-item:nth-child(6n+4) { background-color: var(--pastel-yellow); } .grid-item:nth-child(6n+5) { background-color: var(--pastel-green); } .grid-item:nth-child(6n+6) { background-color: var(--pastel-orange); } .grid-item:hover { transform: translateY(-5px); box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15); transform: translateY(-5px); box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15); } .grid-header { padding: 15px; display: flex; flex-direction: column; background-color: rgba(255, 255, 255, 0.7); backdrop-filter: blur(5px); padding: 15px; display: flex; flex-direction: column; background-color: rgba(255, 255, 255, 0.7); backdrop-filter: blur(5px); border-bottom: 1px solid rgba(0, 0, 0, 0.05); } .grid-header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .rank-badge { background-color: #1a202c; color: white; font-size: 0.8rem; font-weight: 600; padding: 4px 8px; border-radius: 50px; display: inline-block; } background-color: #1a202c; color: white; font-size: 0.8rem; font-weight: 600; padding: 4px 8px; border-radius: 50px; display: inline-block; } .grid-header h3 { margin: 0; font-size: 1.2rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; font-size: 1.2rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .grid-meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; } .owner-info { color: var(--text-secondary); font-weight: 500; } .owner-info { color: var(--text-secondary); font-weight: 500; } .likes-counter { display: flex; align-items: center; color: #e53e3e; font-weight: 600; } .likes-counter span { margin-left: 4px; display: flex; align-items: center; color: #e53e3e; font-weight: 600; } .likes-counter span { margin-left: 4px; } .grid-actions { padding: 10px 15px; text-align: right; background-color: rgba(255, 255, 255, 0.7); backdrop-filter: blur(5px); position: absolute; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: flex-end; } padding: 10px 15px; text-align: right; background-color: rgba(255, 255, 255, 0.7); backdrop-filter: blur(5px); position: absolute; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: flex-end; } .open-link { text-decoration: none; color: #2c5282; font-weight: 600; padding: 5px 10px; border-radius: 5px; transition: all 0.2s; text-decoration: none; color: #2c5282; font-weight: 600; padding: 5px 10px; border-radius: 5px; transition: all 0.2s; background-color: rgba(237, 242, 247, 0.8); } .open-link:hover { background-color: #e2e8f0; } .grid-content { position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding-top: 85px; /* Header height */ padding-bottom: 45px; /* Actions height */ } position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding-top: 85px; padding-bottom: 45px; } .iframe-container { width: 100%; height: 100%; overflow: hidden; position: relative; width: 100%; height: 100%; overflow: hidden; position: relative; } /* Apply 70% scaling to iframes */ .grid-content iframe { transform: scale(0.7); transform-origin: top left; width: 142.857%; height: 142.857%; border: none; border-radius: 0; } transform: scale(0.7); transform-origin: top left; width: 142.857%; height: 142.857%; border: none; border-radius: 0; } .error-placeholder { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px; background-color: rgba(255, 255, 255, 0.9); text-align: center; } position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px; background-color: rgba(255, 255, 255, 0.9); text-align: center; } .error-emoji { font-size: 6rem; margin-bottom: 1.5rem; animation: bounce 1s infinite alternate; font-size: 6rem; margin-bottom: 1.5rem; animation: bounce 1s infinite alternate; text-shadow: 0 10px 20px rgba(0,0,0,0.1); } @keyframes bounce { from { transform: translateY(0px) scale(1); } to { transform: translateY(-15px) scale(1.1); } from { transform: translateY(0px) scale(1); } to { transform: translateY(-15px) scale(1.1); } } /* Pagination Styling */ .pagination { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 2rem 0; display: flex; justify-content: center; align-items: center; gap: 10px; margin: 2rem 0; } .pagination-button { background-color: white; border: none; padding: 10px 20px; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; color: var(--text-primary); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); background-color: white; border: none; padding: 10px 20px; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; color: var(--text-primary); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); } .pagination-button:hover { background-color: #f8f9fa; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); background-color: #f8f9fa; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); } .pagination-button.active { background-color: var(--pastel-purple); color: #4a5568; background-color: var(--pastel-purple); color: #4a5568; } .pagination-button:disabled { background-color: #edf2f7; color: #a0aec0; cursor: default; box-shadow: none; background-color: #edf2f7; color: #a0aec0; cursor: default; box-shadow: none; } /* Loading Indicator */ .loading { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255, 255, 255, 0.8); backdrop-filter: blur(5px); display: flex; justify-content: center; align-items: center; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255, 255, 255, 0.8); backdrop-filter: blur(5px); display: flex; justify-content: center; align-items: center; z-index: 1000; } .loading-content { text-align: center; } .loading-content { text-align: center; } .loading-spinner { width: 60px; height: 60px; border: 5px solid #e2e8f0; border-top-color: var(--pastel-purple); border-radius: 50%; width: 60px; height: 60px; border: 5px solid #e2e8f0; border-top-color: var(--pastel-purple); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 15px; } .loading-text { font-size: 1.2rem; font-weight: 600; color: #4a5568; font-size: 1.2rem; font-weight: 600; color: #4a5568; } .loading-error { display: none; margin-top: 10px; color: #e53e3e; font-size: 0.9rem; display: none; margin-top: 10px; color: #e53e3e; font-size: 0.9rem; } /* Stats window styling */ .stats-window { margin-top: 2rem; margin-bottom: 2rem; margin-top: 2rem; margin-bottom: 2rem; } .stats-header { display: flex; justify-content: space-between; align-items: center; display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; } .stats-title { font-size: 1.5rem; font-weight: 700; color: #2d3748; font-size: 1.5rem; font-weight: 700; color: #2d3748; } .stats-toggle { background-color: var(--pastel-blue); border: none; padding: 8px 16px; border-radius: 20px; font-weight: 600; cursor: pointer; transition: all 0.2s; } background-color: var(--pastel-blue); border: none; padding: 8px 16px; border-radius: 20px; font-weight: 600; cursor: pointer; transition: all 0.2s; } .stats-toggle:hover { background-color: var(--pastel-purple); } .stats-content { background-color: white; border-radius: 10px; padding: 20px; box-shadow: var(--box-shadow); max-height: 0; overflow: hidden; transition: max-height 0.5s ease-out; background-color: white; border-radius: 10px; padding: 20px; box-shadow: var(--box-shadow); max-height: 0; overflow: hidden; transition: max-height 0.5s ease-out; } .stats-content.open { max-height: 600px; } .chart-container { width: 100%; height: 500px; width: 100%; height: 500px; } /* Responsive Design */ @media (max-width: 768px) { body { padding: 1rem; } .grid-container { grid-template-columns: 1fr; } body { padding: 1rem; } .grid-container { grid-template-columns: 1fr; } .search-bar { flex-direction: column; padding: 10px; flex-direction: column; padding: 10px; } .search-bar input { width: 100%; margin-bottom: 10px; width: 100%; margin-bottom: 10px; } .search-bar .refresh-btn { width: 100%; justify-content: center; } .pagination { flex-wrap: wrap; } .chart-container { height: 300px; width: 100%; justify-content: center; } .pagination { flex-wrap: wrap; } .chart-container { height: 300px; } } .error-emoji-detector { position: fixed; top: -9999px; left: -9999px; z-index: -1; opacity: 0; }
/* ์ถ๊ฐ ๋ ์ด์์ ์์ (์๋ฐํ, ZERO GPU ๋ฑ์ง ๋ฑ)์ ์ํด ์๋ ํด๋์ค๋ค์ ์ผ๋ถ ์ถ๊ฐ/์์ ํด๋ ์ข์ง๋ง ์์๋ ์ ์์ญ์์ ์ด๋ฏธ ์ถฉ๋ถํ ์ฒ๋ฆฌํ๋ฏ๋ก ์๋ต */ /* ๋ค์ ๋ถ๋ถ์ Zero GPU Spaces์ฉ ์นด๋ ๊ตฌ์กฐ์์ ํ์ฉ */ position: fixed; top: -9999px; left: -9999px; z-index: -1; opacity: 0; } .space-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; } .avatar-img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid #ccc; width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid #ccc; } .space-title { font-size: 1rem; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; font-size: 1rem; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; } .zero-gpu-badge { font-size: 0.7rem; background-color: #e6fffa; color: #319795; border: 1px solid #81e6d9; border-radius: 6px; padding: 2px 6px; font-weight: 600; margin-left: 8px; font-size: 0.7rem; background-color: #e6fffa; color: #319795; border: 1px solid #81e6d9; border-radius: 6px; padding: 2px 6px; font-weight: 600; margin-left: 8px; } .desc-text { font-size: 0.85rem; color: #444; margin: 4px 0; line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; font-size: 0.85rem; color: #444; margin: 4px 0; line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; } .author-name { font-size: 0.8rem; color: #666; font-size: 0.8rem; color: #666; } .likes-wrapper { display: flex; align-items: center; gap: 4px; color: #e53e3e; font-weight: bold; font-size: 0.85rem; display: flex; align-items: center; gap: 4px; color: #e53e3e; font-weight: bold; font-size: 0.85rem; } .likes-heart { font-size: 1rem; line-height: 1rem; color: #f56565; font-size: 1rem; line-height: 1rem; color: #f56565; } /* ์ด๋ชจ์ง ์ ์ฉ ์คํ์ผ (์ ํ์ฌํญ) */ .emoji-avatar { font-size: 1.2rem; width: 32px; height: 32px; border-radius: 50%; border: 1px solid #ccc; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; width: 32px; height: 32px; border-radius: 50%; border: 1px solid #ccc; display: flex; align-items: center; justify-content: center; } </style></head>8 unmodified lines </div> <div class="mac-title">Huggingface Explorer</div> </div> <div class="mac-content"> <div class="header"> <!-- ์ฒซ ๋ฒ์งธ ํญ ์ ๋ชฉ์ Zero GPU Spaces๋ก ๋ณ๊ฒฝ --> <h1>ZeroGPU Spaces Leaderboard</h1> <p>Discover Zero GPU(Shared A100) spaces from Hugging Face</p> </div> <!-- Tab Navigation --> <div class="tab-nav"> <button id="tabTrendingButton" class="tab-button active">Trending</button> <button id="tabFixedButton" class="tab-button">Picks</button> </div> <!-- Trending(Zero GPU) Tab Content --> <div id="trendingTab" class="tab-content active"> <div class="stats-window mac-window"> <div class="mac-toolbar">16 unmodified lines </div> </div> </div> <div class="search-bar"> <input type="text" id="searchInput" placeholder="Search by name, owner, or description..." /> <button id="refreshButton" class="refresh-btn">1 unmodified line Refresh </button> </div> <div id="gridContainer" class="grid-container"></div> <div id="pagination" class="pagination"></div> </div> <!-- Fixed Tab Content (๊ธฐ์กด ์์ ์ ์ง) --> <div id="fixedTab" class="tab-content"> <div id="fixedGrid" class="grid-container"></div> </div> </div> </div> </div> <div id="loadingIndicator" class="loading"> <div class="loading-content"> <div class="loading-spinner"></div> <div class="loading-text">Loading Zero-GPU spaces...</div> <div id="loadingError" class="loading-error"> If this takes too long, try refreshing the page. </div> <div id="loadingError" class="loading-error">If this takes too long, try refreshing the page.</div> </div> </div> <script> // DOM Elements // ------------------- Front-End JS (๋์ผ) ------------------- const elements = { gridContainer: document.getElementById('gridContainer'), loadingIndicator: document.getElementById('loadingIndicator'),5 unmodified lines statsContent: document.getElementById('statsContent'), creatorStatsChart: document.getElementById('creatorStatsChart') }; const tabTrendingButton = document.getElementById('tabTrendingButton'); const tabFixedButton = document.getElementById('tabFixedButton'); const trendingTab = document.getElementById('trendingTab');4 unmodified lines isLoading: false, spaces: [], currentPage: 0, itemsPerPage: 24, // Changed from 72 to 24 itemsPerPage: 24, totalItems: 0, loadingTimeout: null, staticModeAttempted: {},3 unmodified lines iframeStatuses: {} };
// Advanced iframe loader for better error detection // iframe ๋ก๋ฉ ๋ฐ ์๋ฌ ๊ฐ์ง const iframeLoader = { checkQueue: {}, maxAttempts: 5, checkInterval: 5000, startChecking: function(iframe, owner, name, title, spaceKey) { startChecking(iframe, owner, name, title, spaceKey) { this.checkQueue[spaceKey] = { iframe: iframe, owner: owner, name: name, title: title, attempts: 0, status: 'loading' iframe, owner, name, title, attempts: 0, status: 'loading' }; this.checkIframeStatus(spaceKey); }, checkIframeStatus: function(spaceKey) { checkIframeStatus(spaceKey) { if (!this.checkQueue[spaceKey]) return; const item = this.checkQueue[spaceKey]; if (item.status !== 'loading') { delete this.checkQueue[spaceKey]; return; } item.attempts++; try { if (!item.iframe || !item.iframe.parentNode) { delete this.checkQueue[spaceKey]; return; }
// Check if content loaded try { const hasContent = item.iframe.contentWindow && item.iframe.contentWindow.document && const hasContent = item.iframe.contentWindow && item.iframe.contentWindow.document && item.iframe.contentWindow.document.body; if (hasContent && if (hasContent && item.iframe.contentWindow.document.body.innerHTML.length > 100) { item.iframe.contentWindow.document.body.innerHTML.length > 100) { const bodyText = item.iframe.contentWindow.document.body.textContent.toLowerCase(); if (bodyText.includes('forbidden') || bodyText.includes('404') || bodyText.includes('not found') || bodyText.includes('error')) { if (bodyText.includes('forbidden') || bodyText.includes('404') || bodyText.includes('not found') || bodyText.includes('error')) { item.status = 'error'; handleIframeError(item.iframe, item.owner, item.name, item.title); } else {3 unmodified lines return; } } catch(e) { // Cross-origin issues can happen; not always an error // ํฌ๋ก์ค ๋๋ฉ์ธ ์๋ฌ๋ ๋จ์๋ฌด์ }
// Check if iframe is visible const rect = item.iframe.getBoundingClientRect(); if (rect.width > 50 && rect.height > 50 && item.attempts > 2) { item.status = 'success'; delete this.checkQueue[spaceKey]; return; }
// If max attempts reached if (item.attempts >= this.maxAttempts) { if (item.iframe.offsetWidth > 0 && item.iframe.offsetHeight > 0) { item.status = 'success';4 unmodified lines delete this.checkQueue[spaceKey]; return; }
// Re-check after some delay const nextDelay = this.checkInterval * Math.pow(1.5, item.attempts - 1); setTimeout(() => this.checkIframeStatus(spaceKey), nextDelay);
} catch (e) { console.error('Error checking iframe status:', e); if (item.attempts >= this.maxAttempts) {11 unmodified lines state.statsVisible = !state.statsVisible; elements.statsContent.classList.toggle('open', state.statsVisible); elements.statsToggle.textContent = state.statsVisible ? 'Hide Stats' : 'Show Stats'; if (state.statsVisible && state.topOwners.length > 0) { renderCreatorStats(); } }
function renderCreatorStats() { if (state.chartInstance) { state.chartInstance.destroy();1 unmodified line const ctx = elements.creatorStatsChart.getContext('2d'); const labels = state.topOwners.map(item => item[0]); const data = state.topOwners.map(item => item[1]);
const colors = []; for (let i = 0; i < labels.length; i++) { const hue = (i * 360 / labels.length) % 360; for (let i=0; i<labels.length; i++) { const hue = (i*360/labels.length) % 360; colors.push(`hsla(${hue}, 70%, 80%, 0.7)`); }
state.chartInstance = new Chart(ctx, { type: 'bar', data: { labels: labels, labels, datasets: [{ label: 'Number of Spaces in Top 500', data: data, data, backgroundColor: colors, borderColor: colors.map(color => color.replace('0.7', '1')), borderColor: colors.map(c => c.replace('0.7', '1')), borderWidth: 1 }] },5 unmodified lines legend: { display: false }, tooltip: { callbacks: { title: function(tooltipItems) { return tooltipItems[0].label; }, label: function(context) { return `Spaces: ${context.raw}`; } title(tooltipItems) { return tooltipItems[0].label; }, label(context) { return `Spaces: ${context.raw}`; } } } }, scales: { x: { beginAtZero: true, title: { display: true, text: 'Number of Spaces' } title: { display: true, text: 'Number of Spaces' } }, y: { title: { display: true, text: 'Creator ID' }, title: { display: true, text: 'Creator ID' }, ticks: { autoSkip: false, font: function(context) { font(context) { const defaultSize = 11; return { size: labels.length > 20 ? defaultSize - 1 : defaultSize }; return { size: labels.length>20 ? defaultSize-1 : defaultSize }; } } }1 unmodified line } }); }
async function loadSpaces(page = 0) { async function loadSpaces(page=0) { setLoading(true); try { const searchText = elements.searchInput.value; const offset = page * state.itemsPerPage;
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Request timeout')), 30000) ); const timeoutPromise = new Promise((_, reject) => { setTimeout(() => reject(new Error('Request timeout')), 30000); }); const fetchPromise = fetch( `/api/trending-spaces?search=${encodeURIComponent(searchText)}&offset=${offset}&limit=${state.itemsPerPage}` );7 unmodified lines
renderGrid(state.spaces); renderPagination();
if (state.statsVisible && state.topOwners.length > 0) { if (state.statsVisible && state.topOwners.length>0) { renderCreatorStats(); } } catch (error) {14 unmodified lines setLoading(false); } }
function renderPagination() { elements.pagination.innerHTML = ''; const totalPages = Math.ceil(state.totalItems / state.itemsPerPage);
// Previous page const prevButton = document.createElement('button'); prevButton.className = 'pagination-button'; prevButton.textContent = 'Previous'; prevButton.disabled = (state.currentPage === 0); prevButton.addEventListener('click', () => { if (state.currentPage > 0) { loadSpaces(state.currentPage - 1); } if (state.currentPage>0) loadSpaces(state.currentPage-1); }); elements.pagination.appendChild(prevButton);
const maxButtons = 7; let startPage = Math.max(0, state.currentPage - Math.floor(maxButtons / 2)); let endPage = Math.min(totalPages - 1, startPage + maxButtons - 1);
if (endPage - startPage + 1 < maxButtons) { startPage = Math.max(0, endPage - maxButtons + 1); let startPage = Math.max(0, state.currentPage - Math.floor(maxButtons/2)); let endPage = Math.min(totalPages-1, startPage + maxButtons -1); if (endPage-startPage+1 < maxButtons) { startPage = Math.max(0, endPage-maxButtons+1); }
for (let i = startPage; i <= endPage; i++) { for (let i=startPage; i<=endPage; i++) { const pageButton = document.createElement('button'); pageButton.className = 'pagination-button' + (i === state.currentPage ? ' active' : ''); pageButton.textContent = (i + 1); pageButton.className = 'pagination-button' + (i===state.currentPage ? ' active' : ''); pageButton.textContent = (i+1); pageButton.addEventListener('click', () => { if (i !== state.currentPage) { loadSpaces(i); } if (i!==state.currentPage) loadSpaces(i); }); elements.pagination.appendChild(pageButton); }
// Next page const nextButton = document.createElement('button'); nextButton.className = 'pagination-button'; nextButton.textContent = 'Next'; nextButton.disabled = (state.currentPage >= totalPages - 1); nextButton.disabled = (state.currentPage >= totalPages-1); nextButton.addEventListener('click', () => { if (state.currentPage < totalPages - 1) { loadSpaces(state.currentPage + 1); if (state.currentPage < totalPages-1) { loadSpaces(state.currentPage+1); } }); elements.pagination.appendChild(nextButton); }
function handleIframeError(iframe, owner, name, title) { const container = iframe.parentNode; const errorPlaceholder = document.createElement('div'); errorPlaceholder.className = 'error-placeholder'; const errorMessage = document.createElement('p'); errorMessage.textContent = `"${title}" space couldn't be loaded`; errorPlaceholder.appendChild(errorMessage);
const directLink = document.createElement('a'); directLink.href = `https://huggingface.co/spaces/${owner}/${name}`; directLink.target = '_blank';5 unmodified lines directLink.style.background = '#ebf8ff'; directLink.style.borderRadius = '5px'; directLink.style.fontWeight = '600';
errorPlaceholder.appendChild(directLink); iframe.style.display = 'none'; container.appendChild(errorPlaceholder); }
function renderGrid(spaces) { elements.gridContainer.innerHTML = ''; if (!spaces || spaces.length === 0) { if (!spaces || spaces.length===0) { const noResultsMsg = document.createElement('p'); noResultsMsg.textContent = 'No zero-gpu spaces found matching your search.'; noResultsMsg.style.padding = '2rem';3 unmodified lines elements.gridContainer.appendChild(noResultsMsg); return; }
spaces.forEach((item) => { spaces.forEach(item => { try { const { url, title, likes_count, owner, name, rank, description, avatar_url, author_name, embedUrl } = item;
const { url, title, likes_count, owner, name, rank, description, avatar_url, author_name, embedUrl } = item; const gridItem = document.createElement('div'); gridItem.className = 'grid-item';
// ์๋จ ํค๋ const headerDiv = document.createElement('div'); headerDiv.className = 'grid-header';
// space-header (์์ + ์ ๋ชฉ + Zero GPU ๋ฐฐ์ง) const spaceHeader = document.createElement('div'); spaceHeader.className = 'space-header';
// 1) ์๋จ ์์ ๋ฑ์ง const rankBadge = document.createElement('div'); rankBadge.className = 'rank-badge'; rankBadge.textContent = `#${rank}`; rankBadge.textContent = `#${rank}`; spaceHeader.appendChild(rankBadge);
// ์ ๋ชฉ+๋ฐฐ์ง const titleWrapper = document.createElement('div'); titleWrapper.style.display = 'flex'; titleWrapper.style.alignItems = 'center';9 unmodified lines zeroGpuBadge.className = 'zero-gpu-badge'; zeroGpuBadge.textContent = 'ZERO GPU'; titleWrapper.appendChild(zeroGpuBadge);
spaceHeader.appendChild(titleWrapper); headerDiv.appendChild(spaceHeader);
// ํ๋จ ๋ฉํ ์ ๋ณด const metaInfo = document.createElement('div'); metaInfo.className = 'grid-meta'; metaInfo.style.display = 'flex';1 unmodified line metaInfo.style.alignItems = 'center'; metaInfo.style.marginTop = '6px';
// ์ผ์ชฝ: (์ค๋ณต rank ์ ๊ฑฐ) const leftMeta = document.createElement('div');
const authorSpan = document.createElement('span'); authorSpan.className = 'author-name'; authorSpan.style.marginLeft = '8px'; authorSpan.textContent = `by ${author_name}`; leftMeta.appendChild(authorSpan);
metaInfo.appendChild(leftMeta);
// ์ค๋ฅธ์ชฝ: likes const likesDiv = document.createElement('div'); likesDiv.className = 'likes-wrapper'; likesDiv.innerHTML = `<span class="likes-heart">โฅ</span><span>${likes_count}</span>`;2 unmodified lines headerDiv.appendChild(metaInfo); gridItem.appendChild(headerDiv);
// description if (description) { const descP = document.createElement('p'); descP.className = 'desc-text'; descP.textContent = description; gridItem.appendChild(descP); }
// iframe container const content = document.createElement('div'); content.className = 'grid-content';
1 unmodified line iframeContainer.className = 'iframe-container';
const iframe = document.createElement('iframe'); iframe.src = embedUrl; // transformed direct URL iframe.src = embedUrl; iframe.title = title; iframe.allow = 'accelerometer; camera; encrypted-media; geolocation; gyroscope;'; iframe.setAttribute('allowfullscreen', ''); iframe.setAttribute('frameborder', '0'); iframe.setAttribute('allowfullscreen',''); iframe.setAttribute('frameborder','0'); iframe.loading = 'lazy';
const spaceKey = `${owner}/${name}`;7 unmodified lines state.iframeStatuses[spaceKey] = 'error'; }; setTimeout(() => { if (state.iframeStatuses[spaceKey] === 'loading') { if (state.iframeStatuses[spaceKey]==='loading') { handleIframeError(iframe, owner, name, title); state.iframeStatuses[spaceKey] = 'error'; }2 unmodified lines iframeContainer.appendChild(iframe); content.appendChild(iframeContainer);
// actions const actions = document.createElement('div'); actions.className = 'grid-actions';
6 unmodified lines actions.appendChild(linkEl); gridItem.appendChild(content); gridItem.appendChild(actions);
elements.gridContainer.appendChild(gridItem);
} catch (err) { console.error('Item rendering error:', err); } }); }
############# Picks URL ์
๋ ฅ
function renderFixedGrid() { // Fixed Tab ์์์ฉ (์๋ณธ ์ฝ๋ ์์ ์ ์ง) // ์์ Picks fixedGridContainer.innerHTML = '';
const staticSpaces = [ { url: "https://huggingface.co/spaces/VIDraft/SanaSprint",10 unmodified lines owner: "VIDraft", name: "SanaSprint", rank: 2 }, { url: "https://huggingface.co/spaces/VIDraft/SanaSprint", title: "SanaSprint", likes_count: 0, owner: "VIDraft", name: "SanaSprint", rank: 3 } ];
if (!staticSpaces || staticSpaces.length === 0) { if (!staticSpaces || staticSpaces.length===0) { const noResultsMsg = document.createElement('p'); noResultsMsg.textContent = 'No spaces to display.'; noResultsMsg.style.padding = '2rem';3 unmodified lines fixedGridContainer.appendChild(noResultsMsg); return; }
staticSpaces.forEach((item) => { staticSpaces.forEach(item => { try { const { url, title, likes_count, owner, name, rank } = item; const gridItem = document.createElement('div');1 unmodified line
const header = document.createElement('div'); header.className = 'grid-header';
const headerTop = document.createElement('div'); headerTop.className = 'grid-header-top';
// ๋ก๋ด ์ด๋ชจ์ง + ํ์ดํ ํจ๊ป ํ์ const leftWrapper = document.createElement('div'); leftWrapper.style.display = 'flex'; leftWrapper.style.alignItems = 'center';
const emojiAvatar = document.createElement('div'); emojiAvatar.className = 'emoji-avatar'; emojiAvatar.textContent = '๐ค';3 unmodified lines titleEl.textContent = title; titleEl.title = title; leftWrapper.appendChild(titleEl);
headerTop.appendChild(leftWrapper);
const rankBadge = document.createElement('div');2 unmodified lines headerTop.appendChild(rankBadge);
header.appendChild(headerTop);
const metaInfo = document.createElement('div'); metaInfo.className = 'grid-meta';
12 unmodified lines
const content = document.createElement('div'); content.className = 'grid-content';
const iframeContainer = document.createElement('div'); iframeContainer.className = 'iframe-container';
1 unmodified line iframe.src = "https://" + owner.toLowerCase() + "-" + name.toLowerCase() + ".hf.space"; iframe.title = title; iframe.allow = 'accelerometer; camera; encrypted-media; geolocation; gyroscope;'; iframe.setAttribute('allowfullscreen', ''); iframe.setAttribute('frameborder', '0'); iframe.setAttribute('allowfullscreen',''); iframe.setAttribute('frameborder','0'); iframe.loading = 'lazy';
const spaceKey = `${owner}/${name}`;4 unmodified lines handleIframeError(iframe, owner, name, title); }; setTimeout(() => { if (iframe.offsetWidth === 0 || iframe.offsetHeight === 0) { if (iframe.offsetWidth===0 || iframe.offsetHeight===0) { handleIframeError(iframe, owner, name, title); } }, 30000);3 unmodified lines
const actions = document.createElement('div'); actions.className = 'grid-actions';
const linkEl = document.createElement('a'); linkEl.href = url; linkEl.target = '_blank';3 unmodified lines
gridItem.appendChild(content); gridItem.appendChild(actions);
fixedGridContainer.appendChild(gridItem);
} catch (error) { console.error('Fixed tab rendering error:', error); } }); }
// Tab switching tabTrendingButton.addEventListener('click', () => { tabTrendingButton.classList.add('active'); tabFixedButton.classList.remove('active');8 unmodified lines trendingTab.classList.remove('active'); renderFixedGrid(); });
elements.searchInput.addEventListener('input', () => { clearTimeout(state.searchTimeout); state.searchTimeout = setTimeout(() => loadSpaces(0), 300); }); elements.searchInput.addEventListener('keyup', (event) => { if (event.key === 'Enter') { if (event.key==='Enter') { loadSpaces(0); } });3 unmodified lines window.addEventListener('load', function() { setTimeout(() => loadSpaces(0), 500); });
setTimeout(() => { if (state.isLoading) { setLoading(false);15 unmodified lines function setLoading(isLoading) { state.isLoading = isLoading; elements.loadingIndicator.style.display = isLoading ? 'flex' : 'none';
if (isLoading) { elements.refreshButton.classList.add('refreshing'); clearTimeout(state.loadingTimeout);11 unmodified lines</html>''')
# Flask ์ฑ ์คํ (ํฌํธ 7860) # Flask ์คํ app.run(host='0.0.0.0', port=7860)
app.py+287-770