Spaces:
Sleeping
Sleeping
File size: 1,184 Bytes
e498871 dcc9dbd e498871 dcc9dbd e498871 dcc9dbd e498871 dcc9dbd e498871 dcc9dbd e498871 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#!/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() |