Spaces:
Running
Running
""" | |
RoutePilot - GNN-LLM Intelligent Selection System | |
Hugging Face Spaces Entry Point | |
This is the main entry point for the Hugging Face Spaces deployment. | |
It imports the necessary components from the existing application and | |
sets up the Gradio interface for deployment. | |
""" | |
import os | |
import sys | |
import gradio as gr | |
# Add the current directory to Python path for imports | |
sys.path.append(os.path.dirname(__file__)) | |
# Import the main application components | |
from demo import create_interface | |
# Set up environment variables for Hugging Face Spaces | |
def setup_environment(): | |
"""Set up environment variables for Hugging Face Spaces deployment""" | |
# Check if we're running on Hugging Face Spaces | |
if os.getenv("SPACE_ID"): | |
print("π Running on Hugging Face Spaces") | |
# Check for NVIDIA API key | |
if not os.getenv("NVIDIA_API_KEY"): | |
print("β οΈ NVIDIA_API_KEY not set in Space secrets.") | |
print(" Please set NVIDIA_API_KEY in the Space Repository Secrets.") | |
print(" Some features may be limited without API access.") | |
else: | |
print("β NVIDIA_API_KEY found in Space secrets") | |
# Set CUDA device for Spaces (usually limited resources) | |
os.environ["CUDA_VISIBLE_DEVICES"] = "0" | |
# Set memory optimization flags | |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128" | |
else: | |
print("π Running locally") | |
# Check for local .env file | |
if not os.getenv("NVIDIA_API_KEY"): | |
print("βΉοΈ NVIDIA_API_KEY not found. For local development, create a .env file") | |
print(" or set the environment variable manually.") | |
def main(): | |
"""Main function to launch the application""" | |
# Set up environment | |
setup_environment() | |
# Create the Gradio interface | |
print("π― Creating RoutePilot interface...") | |
demo = create_interface() | |
# Launch the application | |
# For Hugging Face Spaces, we don't need to specify server_name and port | |
# The platform handles this automatically | |
demo.launch( | |
show_error=True, | |
debug=False, # Set to False for production | |
show_api=False | |
) | |
if __name__ == "__main__": | |
main() |