import sys import os from huggingface_hub import HfApi # Force UTF-8 encoding for stdout/stderr to handle emojis sys.stdout.reconfigure(encoding='utf-8') sys.stderr.reconfigure(encoding='utf-8') SPACE_ID = "Kraft102/widgetdc-cortex" def fetch_logs(): api = HfApi() print(f"📊 Fetching status for Space: {SPACE_ID}") try: # Get Space Status info = api.space_info(repo_id=SPACE_ID) print(f" Status: {info.runtime.stage}") print(f" Hardware: {info.runtime.hardware}") # Unfortunately, getting raw logs programmatically via this API is limited without specific calls. # But we can try to see if there are any hints in the runtime info. # If the stage is "BUILD_ERROR" or "RUNTIME_ERROR", it's bad. if info.runtime.stage in ["BUILD_ERROR", "RUNTIME_ERROR"]: print(f"❌ Critical Error: {info.runtime.stage}") elif info.runtime.stage == "RUNNING": print(f"✅ Space is marked RUNNING (but might be failing health check)") else: print(f"⏳ Status: {info.runtime.stage} (Building/Starting)") except Exception as e: print(f"❌ Failed to fetch info: {e}") if __name__ == "__main__": fetch_logs()