yamnet_test / app.py
Luis
add step=1
c30c603
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)