Download test_local.py from gusmoon/TutorIA: direct link, hf CLI and curl.
- Browser
- Download file 3.33 kB
-
https://huggingface.co/spaces/gusmoon/TutorIA/resolve/main/test_local.py
- Command line
-
hf download hf://spaces/gusmoon/TutorIA/test_local.py
-
curl -L -o test_local.py https://huggingface.co/spaces/gusmoon/TutorIA/resolve/main/test_local.py
3.33 kB
| #!/usr/bin/env python3 | |
| """ | |
| Script de prueba local para Tutorial AI App | |
| Ejecuta la aplicación localmente para pruebas antes del despliegue | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| import time | |
| import requests | |
| from threading import Thread | |
| def install_dependencies(): | |
| """Instalar dependencias si no están instaladas""" | |
| print("📦 Instalando dependencias...") | |
| try: | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) | |
| print("✅ Dependencias instaladas correctamente") | |
| except subprocess.CalledProcessError as e: | |
| print(f"❌ Error instalando dependencias: {e}") | |
| return False | |
| return True | |
| def start_app(): | |
| """Iniciar la aplicación Flask""" | |
| print("🚀 Iniciando aplicación...") | |
| os.environ['FLASK_ENV'] = 'development' | |
| os.environ['PORT'] = '7860' | |
| try: | |
| from app import app | |
| app.run(host='0.0.0.0', port=7860, debug=True) | |
| except Exception as e: | |
| print(f"❌ Error iniciando aplicación: {e}") | |
| def test_endpoints(): | |
| """Probar endpoints de la API""" | |
| base_url = "http://localhost:7860" | |
| # Esperar a que la aplicación inicie | |
| print("⏳ Esperando a que la aplicación inicie...") | |
| time.sleep(5) | |
| try: | |
| # Probar endpoint de salud | |
| response = requests.get(f"{base_url}/health") | |
| if response.status_code == 200: | |
| print("✅ Endpoint /health funcionando") | |
| else: | |
| print(f"❌ Endpoint /health falló: {response.status_code}") | |
| # Probar endpoint principal | |
| response = requests.get(base_url) | |
| if response.status_code == 200: | |
| print("✅ Endpoint principal funcionando") | |
| else: | |
| print(f"❌ Endpoint principal falló: {response.status_code}") | |
| # Probar generación de tutorial | |
| print("🧪 Probando generación de tutorial...") | |
| response = requests.post(f"{base_url}/api/generate", | |
| json={"topic": "Instalar Python en Ubuntu"}) | |
| if response.status_code == 201: | |
| print("✅ Generación de tutorial funcionando") | |
| data = response.json() | |
| print(f" Tutorial ID: {data.get('id')}") | |
| print(f" Título: {data.get('title')}") | |
| else: | |
| print(f"❌ Generación de tutorial falló: {response.status_code}") | |
| except requests.exceptions.ConnectionError: | |
| print("❌ No se pudo conectar a la aplicación") | |
| except Exception as e: | |
| print(f"❌ Error en pruebas: {e}") | |
| if __name__ == "__main__": | |
| print("🧪 Tutorial AI App - Prueba Local") | |
| print("=" * 50) | |
| if not install_dependencies(): | |
| sys.exit(1) | |
| # Iniciar aplicación en un hilo separado | |
| app_thread = Thread(target=start_app, daemon=True) | |
| app_thread.start() | |
| # Ejecutar pruebas | |
| test_endpoints() | |
| print("\n📝 Para probar manualmente:") | |
| print(" 1. Ve a http://localhost:7860") | |
| print(" 2. Prueba generar un tutorial") | |
| print(" 3. Verifica que la API funcione correctamente") | |
| print("\n⏹️ Presiona Ctrl+C para detener la aplicación") | |
| try: | |
| while True: | |
| time.sleep(1) | |
| except KeyboardInterrupt: | |
| print("\n👋 Aplicación detenida") | |