File size: 2,643 Bytes
97249f0
 
 
 
 
 
 
 
 
f8c5754
 
 
 
 
97249f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e31b1cf
 
 
c30c603
e31b1cf
97249f0
f8c5754
97249f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import gradio as gr
from test import predict_uri
import sys
import warnings
from fastapi import FastAPI

# ignore UserWarning
warnings.simplefilter("ignore", UserWarning)

# examples = [
#     ['res/miaow_16k.wav'],
#     ['res/snore/pro_snore 6bee45643b45af9b_a7a3bbe6ba79af5b25b19ad10a8d9421d0d5679b.wav'],
#     ['res/snore/Snoring vs Sleep Apnea  - What the difference sounds like.mp4']
# ]
title = "yamnet test"
description = "An audio event classifier trained on the AudioSet dataset to predict audio events from the AudioSet ontology."

# # https://github.com/gradio-app/gradio/issues/2362
# class Logger:
#     def __init__(self, filename):
#         self.terminal = sys.stdout
#         self.log = open(filename, "w")
#
#     def write(self, message):
#         self.terminal.write(message)
#         self.log.write(message)
#
#     def flush(self):
#         self.terminal.flush()
#         self.log.flush()
#
#     def isatty(self):
#         return False
#
#
# sys.stdout = Logger("output.log")
#
#
# def test(x):
#     print("This is a test")
#     print(f"Your function is running with input {x}...")
#     return x
#
#
# def read_logs():
#     sys.stdout.flush()
#     with open("output.log", "r") as f:
#         return f.read()
#
#
# with gr.Interface(predict_uri, inputs=gr.inputs.Audio(type="filepath"), outputs=["text", 'plot']) as demo:
#     examples = examples,
#     title = title,
#     description = description,
#     allow_flagging = 'never'
#
#     logs = gr.Textbox()
#     demo.load(read_logs, None, logs, every=1)
#
# demo.launch(enable_queue=True, show_error=True)


# with gr.Blocks() as demo:
#     with gr.Row():
#         inputs = gr.inputs.Audio(type="filepath")
#         outputs = ["text", 'plot']
#     btn = gr.Button("Run")
#     btn.click(predict_uri, inputs, outputs)
#
#     logs = gr.Textbox()
#     demo.load(read_logs, None, logs, every=1)
#
# demo.queue().launch()


demo = gr.Interface(
    predict_uri,
    inputs=[
        gr.inputs.Audio(type="filepath"),
        gr.inputs.Audio(source="microphone", type="filepath"),
        gr.Slider(minimum=7, maximum=21, step=1)
    ],
    outputs=['image', 'image', 'image', 'text', 'text', 'text', 'text'],
    # examples=examples,
    title=title,
    description=description,
    allow_flagging='never'
)
demo.launch(enable_queue=True, show_error=True, share=False)

# # FastAPI
# CUSTOM_PATH = "/gradio"
#
# app = FastAPI()
#
#
# @app.get("/")
# def read_main():
#     return {"message": "This is your main app"}
#
#
# io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
# app = gr.mount_gradio_app(app, io, path=CUSTOM_PATH)