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"""

{space_name}

Status: {space.get("status", "unknown")}

SDK: {space.get("sdk", "N/A")}

View Space
""" 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"""

Found {len(user_spaces)} public spaces for {USERNAME}

{"".join(get_space_card(space) for space in user_spaces)}
""" 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()