Download app.py from VAH6002/TFA: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/VAH6002/TFA/resolve/main/app.py
- Command line
-
hf download hf://spaces/VAH6002/TFA/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VAH6002/TFA/resolve/main/app.py
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() |