Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python | |
| """ | |
| Textual-Serve app for Hugging Face Spaces | |
| Serves the Textual Calculator example application | |
| """ | |
| import os | |
| from textual_serve.server import Server | |
| def main(): | |
| # Default to calculator, but allow override via environment variable | |
| app_choice = os.environ.get("TEXTUAL_APP", "calculator").lower() | |
| if app_choice == "demo": | |
| # Run the built-in Textual demo | |
| command = "python -m textual" | |
| title = "Textual Demo on HF Spaces" | |
| else: | |
| # Run the calculator example (default) | |
| command = "python calculator.py" | |
| title = "Textual Calculator on HF Spaces" | |
| # Create server configured for HF Spaces | |
| server = Server( | |
| command=command, | |
| host="0.0.0.0", # Accept connections from any IP | |
| port=7860, # HF Spaces default port | |
| title=title, # Browser tab title | |
| # The public_url will be automatically set by HF Spaces | |
| ) | |
| print("Starting Textual-Serve server...") | |
| print(f"Serving: {title}") | |
| print(f"Command: {command}") | |
| print(f"Server will be available on port 7860") | |
| # Start serving | |
| server.serve() | |
| if __name__ == "__main__": | |
| main() |