Fix random_demos.py issues (#9927)

- Removes assumption/requirement that the script is run specifically in the demo/ directory.
- Removes assumption/requirement that there are 3 unwanted large demos that should be removed.  (Note: currently, the `.gradio/flagged` demo isn't there, so it will throw an error.)
This commit is contained in:
meg 2024-11-12 12:47:36 -08:00 committed by GitHub
parent 1555321f6f
commit ceb4005bb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,15 +2,13 @@
Usage: python random_demos.py <num_demos>
Example: python random_demos.py 8
Assumes:
- This is being run from the gradio/demo/ directory
"""
from __future__ import annotations
import argparse
import importlib
import pathlib
import os
import random
@ -21,12 +19,13 @@ parser.add_argument("num_demos", help="number of demos to launch", type=int, def
args = parser.parse_args()
# get the list of directory names
demos_list = next(os.walk('.'))[1]
demos_list = next(os.walk(pathlib.Path(__file__).parent))[1]
# Some demos are just too large or need to be run in a special way, so we'll just skip them
demos_list.remove('streaming_wav2vec')
demos_list.remove('blocks_neural_instrument_coding')
demos_list.remove('.gradio/flagged')
large_demos = ['streaming_wav2vec', 'blocks_neural_instrument_coding', '.gradio/flagged']
for large_demo in large_demos:
if large_demo in demos_list:
demos_list.remove(large_demo)
for d, demo_name in enumerate(random.sample(demos_list, args.num_demos)):
print(f"Launching demo {d+1}/{args.num_demos}: {demo_name}")