import os import gradio as gr from dotenv import load_dotenv # Load environment variables load_dotenv() # Get API token from environment variable API_TOKEN = os.getenv("HUGGINGFACE_TOKEN") # Your private space name SPACE_NAME = "muskan11200/gas-demand-forecast" def main(): if not API_TOKEN: raise ValueError("HUGGINGFACE_TOKEN environment variable is not set") # Load the interface from the private space interface = gr.load( name=SPACE_NAME, src="spaces", hf_token=API_TOKEN ) # Launch the interface interface.launch() if __name__ == "__main__": main() """ Instructions for setting up public-private space connection: 1. Private Space Setup: - Update your private space with the modified code above - The key change is returning the plot as a base64 data URL instead of a file path 2. Public Space Setup: - Create a new space with visibility set to "Public" - Upload this file as app.py - Add your Hugging Face API token as a secret: * Go to your space's Settings > Repository Secrets * Add a new secret named HUGGINGFACE_TOKEN * Paste your API token (from https://huggingface.co/settings/tokens) 3. Requirements: - Add these to requirements.txt: gradio==4.19.2 huggingface_hub>=0.20.3 python-dotenv>=1.0.0 4. Security Notes: - API token is securely stored as an environment variable - The private space's code and data remain secure - Only the interface is exposed through the public space """