import os import requests import gradio as gr from datetime import datetime # Hugging Face Token HF_TOKEN = os.getenv("HF_TOKEN") def get_username_from_token(): """Retrieve the username using the Hugging Face token""" if not HF_TOKEN: return None headers = { "Authorization": f"Bearer {HF_TOKEN}", "Accept": "application/json" } response = requests.get("https://huggingface.co/api/whoami", headers=headers) print(f"Response status: {response.status_code}") print(f"Response content: {response.text}") if response.status_code == 200: return response.json().get("name") return None # Retrieve the username USERNAME = get_username_from_token() if not USERNAME: raise ValueError("Error: Could not retrieve username. Check your Hugging Face token.") 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"""
Repository: {space["repo_id"]}
Private: {space.get("private", False)}
Last Modified: {format_timestamp(space.get("lastModified"))}
Space SDK: {space.get("sdk", "N/A")}