Spaces:
Sleeping

TFA / app.py
VAH6002's picture
Upload app.py
3e0d4ce verified
Raw History Blame Contribute Delete
2.3 kB
#!/usr/bin/env python3
"""
TFA (Test Failure Analysis) - Hugging Face Spaces Entry Point
This is the main entry point for the Hugging Face Spaces deployment.
It launches the Streamlit application with proper configuration.
"""
import os
import sys
import subprocess
from pathlib import Path
# Add the project root to Python path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
def setup_environment():
"""Set up environment for Hugging Face Spaces."""
# Set default environment variables for Spaces
os.environ.setdefault("TFA_ENVIRONMENT", "production")
os.environ.setdefault("TFA_USE_MOCK_DATA", "true") # Use mock data by default
os.environ.setdefault("STREAMLIT_SERVER_PORT", "7860") # HF Spaces default port
os.environ.setdefault("STREAMLIT_SERVER_ADDRESS", "0.0.0.0")
# Set a default API key for demo purposes (users can override via Spaces secrets)
if not os.environ.get("GOOGLE_API_KEY"):
os.environ["GOOGLE_API_KEY"] = "demo-key-for-huggingface-spaces"
print("πŸš€ TFA Application starting on Hugging Face Spaces...")
print(f"πŸ“Š Using mock data: {os.environ.get('TFA_USE_MOCK_DATA', 'true')}")
print(f"πŸ”‘ API Key configured: {'Yes' if os.environ.get('GOOGLE_API_KEY') else 'No'}")
def main():
"""Main entry point for Hugging Face Spaces."""
setup_environment()
# Launch Streamlit app
streamlit_app = project_root / "tfa_ui" / "app.py"
cmd = [
sys.executable, "-m", "streamlit", "run",
str(streamlit_app),
"--server.port", os.environ.get("STREAMLIT_SERVER_PORT", "7860"),
"--server.address", os.environ.get("STREAMLIT_SERVER_ADDRESS", "0.0.0.0"),
"--server.headless", "true",
"--server.enableCORS", "false",
"--server.enableXsrfProtection", "false"
]
print(f"🌐 Starting Streamlit with command: {' '.join(cmd)}")
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"❌ Failed to start Streamlit: {e}")
sys.exit(1)
except KeyboardInterrupt:
print("πŸ‘‹ Shutting down TFA application...")
sys.exit(0)
if __name__ == "__main__":
main()