File size: 942 Bytes
f61429a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()