import requests import gradio as gr from datetime import datetime # 테스트를 위해 Gradio 공식 계정으로 설정 USERNAME = "gradio" 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 search_spaces(): """Search for spaces using the Hugging Face search API""" url = "https://huggingface.co/api/spaces" headers = {"Accept": "application/json"} try: # First, try to get all spaces response = requests.get(url, headers=headers) if response.status_code == 200: all_spaces = response.json() # Filter spaces by username user_spaces = [space for space in all_spaces if space.get('author', '').lower() == USERNAME.lower()] return user_spaces except Exception as e: print(f"Error in search_spaces: {e}") return [] def get_space_card(space): """Generate HTML card for a space""" space_id = space.get('id', '') space_name = space_id.split('/')[-1] if space_id else 'Unknown' return f"""
Author: {space.get('author', 'Unknown')}
SDK: {space.get('sdk', 'N/A')}
Likes: {space.get('likes', 0)} ❤️
This could be because:
Found {len(spaces)} public spaces for {USERNAME}