Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| # Get tokens from environment | |
| ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN") | |
| read_key = os.environ.get('HF_TOKEN') | |
| # Load external app (returns a component) | |
| demo_app = gr.load("userIdc2024/lipsync-video-generator", token=read_key, src="spaces") | |
| # Token verification function | |
| def verify_token(user_token): | |
| if user_token == ACCESS_TOKEN: | |
| return gr.update(visible=True), gr.update(visible=False), "" | |
| else: | |
| return gr.update(visible=False), gr.update(visible=True), "❌ Invalid token. Please try again." | |
| # Build main UI | |
| with gr.Blocks() as protected_app: | |
| gr.Markdown("## 🔐 Enter Access Token to Use the App") | |
| token_input = gr.Textbox(label="Access Token", type="password") | |
| verify_btn = gr.Button("Unlock App") | |
| error_msg = gr.Markdown("", visible=False) | |
| app_container = gr.Column(visible=False) | |
| with app_container: | |
| demo_app.render() # Safe here since it's gr.load() | |
| verify_btn.click( | |
| fn=verify_token, | |
| inputs=token_input, | |
| outputs=[app_container, error_msg, error_msg] | |
| ) | |
| # Launch | |
| protected_app.launch() | |