import requests import gradio as gr from datetime import datetime # 테스트를 위해 Gradio 공식 계정으로 설정 USERNAME = "openfree" def format_timestamp(timestamp): if timestamp: dt = datetime.fromisoformat(timestamp.replace('Z', '+00:00')) return dt.strftime('%Y-%m-%d %H:%M') return 'N/A' def get_space_card(space): """Generate HTML card for a space""" return f"""
""" def get_user_spaces(): # Hugging Face API v2 사용 url = f"https://huggingface.co/api/spaces?search={USERNAME}" headers = { "Accept": "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" } try: response = requests.get(url, headers=headers) print(f"Status Code: {response.status_code}") # 디버깅용 print(f"Response: {response.text[:500]}...") # 디버깅용 if response.status_code != 200: return f"Error: Failed to fetch spaces (Status Code: {response.status_code})" spaces_data = response.json() # 사용자의 spaces만 필터링 user_spaces = [] for space in spaces_data: if space.get('author', {}).get('name', '').lower() == USERNAME.lower(): space_info = { "title": space.get('id', '').split('/')[-1], "description": space.get('description', ''), "url": f"https://huggingface.co/spaces/{space.get('id', '')}", } user_spaces.append(space_info) if not user_spaces: return f"""Try visiting: https://huggingface.co/{USERNAME}
Found {len(user_spaces)} public spaces for {USERNAME}
Error details: {str(e)}
Please try again later or check if the username is correct.