import os import requests import gradio as gr import pandas as pd from datetime import datetime # Hugging Face API URL HF_API_URL = "https://huggingface.co/api/spaces" # Hugging Face Token HF_TOKEN = os.getenv("HF_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): return f"""

{space.get('name', 'N/A')}

Author: {space.get('author', 'N/A')}

SDK: {space.get('sdk', 'N/A')}

Status: {space.get('status', 'N/A')}

Created: {format_timestamp(space.get('createdAt'))}

Updated: {format_timestamp(space.get('updatedAt'))}

""" def get_all_spaces(): if not HF_TOKEN: return "Error: Hugging Face token not found." headers = {"Authorization": f"Bearer {HF_TOKEN}"} response = requests.get(HF_API_URL, headers=headers) if response.status_code != 200: return f"Error: Failed to fetch spaces (Status Code: {response.status_code})" spaces = response.json() if not spaces: return "No Spaces found." # Create HTML grid layout html_content = f"""
{"".join(get_space_card(space) for space in spaces)}
""" return html_content # Creating the Gradio interface app = gr.Interface( fn=get_all_spaces, inputs=None, outputs=gr.HTML(), title="Hugging Face Spaces Dashboard", description="Displays all available Spaces in a grid layout", theme=gr.themes.Soft(), css=""" .gradio-container { max-width: 100% !important; } """ ) # Launch the Gradio app if __name__ == "__main__": app.launch()