import gradio as gr import requests import random import time # Title and description _TITLE = '''# Generate 3D from 2D image''' _DESCRIPTION_HTML = '''
GitHub | LinkedIn | Email
''' # List of Gradio API URLs API_URLS = [ "https://api.zmkj.site/", "https://api1.zmkj.site/", ] # Function to check URL status def check_url_status(url, timeout=5): """ Checks if a given URL responds within the specified timeout. Returns True if the URL responds successfully, False otherwise. """ try: response = requests.get(url, timeout=timeout) return response.ok except requests.exceptions.Timeout: print(f"URL {url} took too long to respond (timeout: {timeout}s).") return False except requests.exceptions.RequestException as e: print(f"Error checking URL {url}: {e}") return False # Main function to generate the HTML content for the Gradio iframe def get_gradio_iframe_content(): """ Checks the API URLs and returns the HTML for the iframe with an active URL. If no URLs are active, it returns HTML with an error message. """ available_urls = [] # Check each URL and collect the ones that are active for url in API_URLS: if check_url_status(url): available_urls.append(url) iframe_src = "about:blank" display_iframe = "none" # Default to hidden iframe loading_message_style = "none" error_message_style = "none" if available_urls: # If at least one URL is active, choose one randomly selected_url = random.choice(available_urls) iframe_src = selected_url display_iframe = "block" # Show the iframe loading_message_style = "none" # Hide the loading message print(f"Loading iframe from URL: {selected_url}") else: # If no URLs are active loading_message_style = "none" error_message_style = "block" # Show the error message print("Sorry, no API URL available.") # Generate the HTML content for the iframe and status messages # All custom CSS has been removed. Layout will rely on default browser/Gradio styles. html_content = f'''
Loading service...
Sorry service not available
''' return html_content # Initialize the Gradio interface with gr.Blocks() as demo: gr.Markdown(_TITLE) gr.HTML(_DESCRIPTION_HTML) gr.HTML(value=get_gradio_iframe_content()) # Launch the Gradio application if __name__ == "__main__": demo.launch(share = True)