import importlib import gradio as gr import os import sys import copy import pathlib os.environ["SYSTEM"] = "pretend-not-spaces" demo_dir = pathlib.Path(__file__).parent / "demos" all_demos = [] for p in os.listdir("./demos"): full_dir = os.path.join(demo_dir, p) is_dir = os.path.isdir(full_dir) no_requirements = not os.path.exists(os.path.join(full_dir, "requirements.txt")) has_app = os.path.exists(os.path.join(full_dir, "run.py")) if is_dir and no_requirements and has_app: all_demos.append(p) to_exclude = ["blocks_demos", "rows_and_columns", "image_classifier_interface_load", "generate_english_german", "all_demos"] all_demos = [d for d in all_demos if d not in to_exclude] demo_module = None with gr.Blocks() as mega_demo: with gr.Tabs(): for demo_name in all_demos: with gr.TabItem(demo_name): old_path = copy.deepcopy(sys.path) sys.path = [os.path.join(demo_dir, demo_name)] + sys.path if demo_module is None: demo_module = importlib.import_module(f"run") else: demo_module = importlib.reload(demo_module) demo_module.demo sys.path = old_path mega_demo.launch()