Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 3,714 Bytes
f61429a 514cd38 f61429a 5b2e51f 059f849 514cd38 059f849 fbd7b3f 514cd38 d51b0b3 059f849 fbd7b3f 059f849 d51b0b3 059f849 fbd7b3f d51b0b3 fbd7b3f d51b0b3 514cd38 059f849 5b2e51f 059f849 5b2e51f d51b0b3 059f849 f61429a fbd7b3f 5b2e51f fbd7b3f f61429a d51b0b3 f61429a fbd7b3f 5b2e51f fbd7b3f f61429a 5b2e51f d51b0b3 2d1b715 d51b0b3 514cd38 d51b0b3 5b2e51f d51b0b3 5b2e51f d51b0b3 514cd38 f61429a 514cd38 059f849 514cd38 d51b0b3 514cd38 f61429a 514cd38 d51b0b3 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
import requests
import gradio as gr
from datetime import datetime
# ํ
์คํธ๋ฅผ ์ํด ์๋ ค์ง ์ฌ์ฉ์๋ก ๋ณ๊ฒฝ
USERNAME = "multimodalart" # ๋ง์ public spaces๋ฅผ ๊ฐ์ง ์ฌ์ฉ์
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):
"""Generate HTML card for a space"""
space_name = space["id"].split('/')[-1] if 'id' in space else space.get('name', 'Unknown')
return f"""
<div style='border: 1px solid #ddd; padding: 15px; margin: 10px; border-radius: 8px;
background-color: white; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
transition: transform 0.2s ease-in-out;'
onmouseover='this.style.transform="scale(1.02)"'
onmouseout='this.style.transform="scale(1)"'>
<h3 style='color: #2d2d2d; margin: 0 0 10px 0;'>
<a href='https://huggingface.co/spaces/{USERNAME}/{space_name}' target='_blank'
style='text-decoration: none; color: #2d2d2d;'>
{space_name}
</a>
</h3>
<p style='margin: 5px 0;'><strong>Status:</strong>
<span style='color: {"green" if space.get("status") == "running" else "orange"}'>
{space.get("status", "unknown")}</span>
</p>
<p style='margin: 5px 0;'><strong>SDK:</strong> {space.get("sdk", "N/A")}</p>
<div style='margin-top: 10px;'>
<a href='https://huggingface.co/spaces/{USERNAME}/{space_name}' target='_blank'
style='background-color: #0084ff; color: white; padding: 5px 10px;
border-radius: 5px; text-decoration: none; display: inline-block;'>
View Space
</a>
</div>
</div>
"""
def get_user_spaces():
# spaces ๊ฒ์ API ์ฌ์ฉ
response = requests.get(
"https://huggingface.co/api/spaces",
params={"search": USERNAME},
headers={"Accept": "application/json"}
)
# ๋๋ฒ๊น
์ ์ํ ์ถ๋ ฅ
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text[:500]}...") # ์๋ต์ ์ฒ์ 500์๋ง ์ถ๋ ฅ
if response.status_code != 200:
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
try:
all_spaces = response.json()
# ํด๋น ์ฌ์ฉ์์ spaces๋ง ํํฐ๋ง
user_spaces = [space for space in all_spaces if space.get('author', '') == USERNAME]
except Exception as e:
return f"Error parsing response: {str(e)}"
if not user_spaces:
return "No public Spaces found for this user."
# Create HTML grid layout with title and count
html_content = f"""
<div style='padding: 20px; background-color: #f5f5f5;'>
<div style='margin-bottom: 20px;'>
<p style='color: #666; margin: 0;'>Found {len(user_spaces)} public spaces for {USERNAME}</p>
</div>
<div style='
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
'>
{"".join(get_space_card(space) for space in user_spaces)}
</div>
</div>
"""
return html_content
# Creating the Gradio interface
app = gr.Interface(
fn=get_user_spaces,
inputs=None,
outputs=gr.HTML(),
title=f"Hugging Face Public Spaces - {USERNAME}",
description=f"Displays public Spaces from {USERNAME}",
theme=gr.themes.Soft(),
css="""
.gradio-container {
max-width: 100% !important;
}
"""
)
# Launch the Gradio app
if __name__ == "__main__":
app.launch() |