Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Hugging Face API URL
|
6 |
+
HF_API_URL = "https://huggingface.co/api/spaces"
|
7 |
+
|
8 |
+
# Hugging Face Token
|
9 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
10 |
+
|
11 |
+
# Function to get all Spaces
|
12 |
+
def get_all_spaces():
|
13 |
+
if not HF_TOKEN:
|
14 |
+
return "Error: Hugging Face token not found."
|
15 |
+
|
16 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
17 |
+
response = requests.get(HF_API_URL, headers=headers)
|
18 |
+
|
19 |
+
if response.status_code != 200:
|
20 |
+
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
21 |
+
|
22 |
+
spaces = response.json()
|
23 |
+
|
24 |
+
if not spaces:
|
25 |
+
return "No Spaces found."
|
26 |
+
|
27 |
+
# Formatting Spaces into a grid
|
28 |
+
space_info = [f"Name: {space['name']}\nSDK: {space['sdk']}\nStatus: {space['status']}" for space in spaces]
|
29 |
+
return "\n\n".join(space_info)
|
30 |
+
|
31 |
+
# Creating the Gradio interface
|
32 |
+
app = gr.Interface(fn=get_all_spaces, inputs=None, outputs="text")
|
33 |
+
|
34 |
+
# Launch the Gradio app
|
35 |
+
app.launch()
|