pyannote-pt-diarization / test_status.py
marcosremar2's picture
Add basic test script for space connectivity
37b89b9
#!/usr/bin/env python3
"""
Script de diagnóstico rápido para verificar status do Space
"""
import requests
import subprocess
import sys
SPACE_URL = "https://marcosremar2-pyannote-pt-diarization.hf.space"
def check_status():
"""Verifica status HTTP e interpreta o resultado"""
print("🔍 DIAGNÓSTICO RÁPIDO DO SPACE")
print("=" * 40)
print(f"🌐 URL: {SPACE_URL}")
try:
response = requests.get(SPACE_URL, timeout=10)
status_code = response.status_code
print(f"📊 Status HTTP: {status_code}")
if status_code == 200:
print("✅ FUNCIONANDO - Space está online e operacional")
return "working"
elif status_code == 503:
print("⚠️ SERVICE UNAVAILABLE - Space existe mas tem erro interno")
print(" 💡 Causas possíveis:")
print(" • Token HUGGINGFACE_TOKEN não configurado")
print(" • Erro no código da aplicação")
print(" • Modelo não conseguiu carregar")
return "error"
elif status_code == 404:
print("❌ NOT FOUND - Space não existe ou URL incorreta")
return "not_found"
elif status_code == 502:
print("⏳ BAD GATEWAY - Space está reiniciando")
return "restarting"
else:
print(f"❓ STATUS DESCONHECIDO: {status_code}")
return "unknown"
except requests.exceptions.Timeout:
print("⏰ TIMEOUT - Space não responde (pode estar carregando)")
return "timeout"
except requests.exceptions.ConnectionError:
print("❌ CONNECTION ERROR - Problema de rede ou space offline")
return "connection_error"
except Exception as e:
print(f"💥 ERRO INESPERADO: {e}")
return "unexpected_error"
def provide_solution(status):
"""Fornece soluções baseadas no status"""
print("\n🔧 PRÓXIMOS PASSOS:")
if status == "working":
print(" 🎉 Space funcionando perfeitamente!")
print(f" 🔗 Acesse: {SPACE_URL}")
elif status == "error":
print(" 🔑 Configurar token do Hugging Face:")
print(" 1. Acesse: https://huggingface.co/spaces/marcosremar2/pyannote-pt-diarization")
print(" 2. Vá em Settings → Variables and secrets")
print(" 3. Adicione HUGGINGFACE_TOKEN com o valor do seu token")
print(" 4. Aguarde 2-5 minutos para restart automático")
elif status == "not_found":
print(" ❗ Verificar se o space foi criado corretamente")
print(" 📝 URL esperada: https://huggingface.co/spaces/marcosremar2/pyannote-pt-diarization")
elif status in ["restarting", "timeout"]:
print(" ⏳ Aguardar alguns minutos e tentar novamente")
print(" 🔄 Space pode estar reiniciando após mudanças")
else:
print(" 🔍 Verificar logs do space no Hugging Face")
print(" 🆘 Se problema persistir, revisar configuração")
def main():
status = check_status()
provide_solution(status)
# Códigos de saída para automação
exit_codes = {
"working": 0,
"error": 1,
"not_found": 2,
"restarting": 1,
"timeout": 1,
"connection_error": 2,
"unexpected_error": 3
}
return exit_codes.get(status, 3)
if __name__ == "__main__":
exit_code = main()
print(f"\n📋 Exit Code: {exit_code}")
sys.exit(exit_code)