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(status_info): | |
with gr.Blocks() as interface: | |
gr.Markdown(f"## Inference Endpoint Status") | |
gr.Markdown(f"### Status Code: {status_info['status_code']}") | |
gr.Markdown(f"### Message: {status_info['message']}") | |
gr.JSON(status_info["response_data"], label="Response Data") | |
return interface | |