Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import time | |
| import random | |
| import os | |
| # Function to simulate the status of the app | |
| def check_app_status(): | |
| # Simulate different app statuses | |
| status_options = [ | |
| "The app is building. Please wait a few moments...", | |
| "The app is restarting. Hold on...", | |
| "The endpoint is starting up. It might take a few minutes...", | |
| "Payment is needed for inferences. Please complete payment to continue.", | |
| "The endpoint is scaled to zero due to inactivity. Starting it now...", | |
| ] | |
| # Simulate a real condition check (for demonstration, we randomly select one status) | |
| current_status = random.choice(status_options) | |
| # If the endpoint is scaled to zero, simulate the time it takes to start | |
| if current_status == "The endpoint is scaled to zero due to inactivity. Starting it now...": | |
| time.sleep(5) # Simulate the time it takes to start the endpoint | |
| # Simulate some delay for other operations (like checking the status) | |
| time.sleep(2) | |
| return "App start up failure, please check back in a day or two" | |
| return current_status | |
| # Function to simulate the button click event in Gradio UI | |
| def get_status(): | |
| return check_app_status() | |
| # Create the Gradio interface | |
| def create_failed_gradio_ui(): | |
| # Define the Gradio interface | |
| interface = gr.Interface( | |
| fn=get_status, # The function to call to get the status | |
| inputs=[], # No inputs; it's just a status display | |
| outputs="text", # Output will be a simple text message | |
| live=True, # Updates automatically when clicked | |
| title="App Status Dashboard", # Title of the Gradio UI | |
| description="This Gradio UI displays the current status of the app. It is only shown when one of the pre-check routines has failed. At this point, there are various reasons why the app might not be working, including endpoint scaling or payment issues.", | |
| ) | |
| # Launch the UI | |
| interface.launch() | |