mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-24 13:01:18 +08:00
Fix issues related to demos in Spaces (#2086)
* skip demos in all_demos that don't run * hack for spaces * put import back * added audio debugger demo * audio fix * fixed audio debugger * testing * test * remove prints * fix * fix * removed import
This commit is contained in:
parent
adf52d2dad
commit
f2733d8f94
demo
gradio
scripts
ui/packages
@ -15,11 +15,17 @@ demo_module = None
|
||||
for p in sorted(os.listdir("./demos")):
|
||||
old_path = copy.deepcopy(sys.path)
|
||||
sys.path = [os.path.join(demo_dir, p)] + sys.path
|
||||
if demo_module is None:
|
||||
demo_module = importlib.import_module(f"run")
|
||||
else:
|
||||
demo_module = importlib.reload(demo_module)
|
||||
all_demos.append((p, demo_module.demo))
|
||||
try: # Some demos may not be runnable because of 429 timeouts, etc.
|
||||
if demo_module is None:
|
||||
demo_module = importlib.import_module(f"run")
|
||||
else:
|
||||
demo_module = importlib.reload(demo_module)
|
||||
all_demos.append((p, demo_module.demo))
|
||||
except Exception as e:
|
||||
p = p + " ❌"
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(f"Error loading demo: {e}")
|
||||
all_demos.append((p, demo))
|
||||
|
||||
with gr.Blocks() as mega_demo:
|
||||
with gr.Tabs():
|
||||
|
BIN
demo/audio_debugger/cantina.wav
Normal file
BIN
demo/audio_debugger/cantina.wav
Normal file
Binary file not shown.
18
demo/audio_debugger/run.py
Normal file
18
demo/audio_debugger/run.py
Normal file
@ -0,0 +1,18 @@
|
||||
import gradio as gr
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
audio_file = os.path.join(os.path.dirname(__file__), "cantina.wav")
|
||||
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
with gr.Tabs():
|
||||
with gr.TabItem("Audio"):
|
||||
gr.Audio(audio_file)
|
||||
with gr.TabItem("Interface"):
|
||||
gr.Interface(lambda x:x, "audio", "audio", examples=[audio_file])
|
||||
with gr.TabItem("console"):
|
||||
gr.Interface(lambda cmd:subprocess.run([cmd], capture_output=True, shell=True).stdout.decode('utf-8').strip(), "text", "text")
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.launch()
|
@ -212,8 +212,8 @@ class App(FastAPI):
|
||||
else:
|
||||
return FileResponse(app.blocks.favicon_path)
|
||||
|
||||
@app.get("/file/{path:path}", dependencies=[Depends(login_check)])
|
||||
def file(path):
|
||||
@app.get("/file={path:path}", dependencies=[Depends(login_check)])
|
||||
def file(path: str):
|
||||
if (
|
||||
app.blocks.encrypt
|
||||
and isinstance(app.blocks.examples, str)
|
||||
|
@ -7,6 +7,7 @@ import argparse
|
||||
|
||||
def copy_all_demos(source_dir: str, dest_dir: str):
|
||||
demos_to_copy = [
|
||||
"audio_debugger",
|
||||
"blocks_essay",
|
||||
"blocks_js_methods",
|
||||
"blocks_layout",
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
const dispatch = createEventDispatcher<{ click: number }>();
|
||||
|
||||
let samples_dir: string = root + "file/";
|
||||
let samples_dir: string = root + "file=";
|
||||
let page = 0;
|
||||
let gallery = headers.length === 1;
|
||||
let paginate = samples.length > samples_per_page;
|
||||
|
@ -11,7 +11,7 @@ export function normalise_file(
|
||||
data: file
|
||||
};
|
||||
} else if (file.is_file) {
|
||||
file.data = root + "file/" + file.name;
|
||||
file.data = root + "file=" + file.name;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user