|
import os |
|
import requests |
|
import gradio as gr |
|
|
|
|
|
HF_API_URL = "https://huggingface.co/api/spaces" |
|
|
|
|
|
HF_TOKEN = os.getenv("HF_TOKEN") |
|
|
|
|
|
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." |
|
|
|
|
|
space_info = [ |
|
f"Name: {space.get('name', 'N/A')}\nSDK: {space.get('sdk', 'N/A')}\nStatus: {space.get('status', 'N/A')}" |
|
for space in spaces |
|
] |
|
return "\n\n".join(space_info) |
|
|
|
|
|
app = gr.Interface(fn=get_all_spaces, inputs=None, outputs="text") |
|
|
|
|
|
app.launch() |
|
|