Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import os | |
import requests | |
import gradio as gr | |
# Hugging Face API URL | |
HF_API_URL = "https://huggingface.co/api/spaces" | |
# Hugging Face Token | |
HF_TOKEN = os.getenv("HF_TOKEN") | |
# Function to get all Spaces | |
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." | |
# Formatting Spaces into a grid | |
space_info = [f"Name: {space['name']}\nSDK: {space['sdk']}\nStatus: {space['status']}" for space in spaces] | |
return "\n\n".join(space_info) | |
# Creating the Gradio interface | |
app = gr.Interface(fn=get_all_spaces, inputs=None, outputs="text") | |
# Launch the Gradio app | |
app.launch() | |