Spaces:
Running
Running
File size: 1,296 Bytes
5d5de7e 5c6624f 5d5de7e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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()
|