Spaces:
Sleeping
Sleeping
add app.py with gradio
Browse files- app.py +103 -0
- requirements.txt +11 -0
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from test import predict_uri
|
3 |
+
import sys
|
4 |
+
import warnings
|
5 |
+
from fastapi import FastAPI
|
6 |
+
|
7 |
+
# ignore UserWarning
|
8 |
+
warnings.simplefilter("ignore", UserWarning)
|
9 |
+
|
10 |
+
# examples = [
|
11 |
+
# ['res/miaow_16k.wav'],
|
12 |
+
# ['res/snore/pro_snore 6bee45643b45af9b_a7a3bbe6ba79af5b25b19ad10a8d9421d0d5679b.wav'],
|
13 |
+
# ['res/snore/Snoring vs Sleep Apnea - What the difference sounds like.mp4']
|
14 |
+
# ]
|
15 |
+
title = "yamnet test"
|
16 |
+
description = "An audio event classifier trained on the AudioSet dataset to predict audio events from the AudioSet ontology."
|
17 |
+
|
18 |
+
# # https://github.com/gradio-app/gradio/issues/2362
|
19 |
+
# class Logger:
|
20 |
+
# def __init__(self, filename):
|
21 |
+
# self.terminal = sys.stdout
|
22 |
+
# self.log = open(filename, "w")
|
23 |
+
#
|
24 |
+
# def write(self, message):
|
25 |
+
# self.terminal.write(message)
|
26 |
+
# self.log.write(message)
|
27 |
+
#
|
28 |
+
# def flush(self):
|
29 |
+
# self.terminal.flush()
|
30 |
+
# self.log.flush()
|
31 |
+
#
|
32 |
+
# def isatty(self):
|
33 |
+
# return False
|
34 |
+
#
|
35 |
+
#
|
36 |
+
# sys.stdout = Logger("output.log")
|
37 |
+
#
|
38 |
+
#
|
39 |
+
# def test(x):
|
40 |
+
# print("This is a test")
|
41 |
+
# print(f"Your function is running with input {x}...")
|
42 |
+
# return x
|
43 |
+
#
|
44 |
+
#
|
45 |
+
# def read_logs():
|
46 |
+
# sys.stdout.flush()
|
47 |
+
# with open("output.log", "r") as f:
|
48 |
+
# return f.read()
|
49 |
+
#
|
50 |
+
#
|
51 |
+
# with gr.Interface(predict_uri, inputs=gr.inputs.Audio(type="filepath"), outputs=["text", 'plot']) as demo:
|
52 |
+
# examples = examples,
|
53 |
+
# title = title,
|
54 |
+
# description = description,
|
55 |
+
# allow_flagging = 'never'
|
56 |
+
#
|
57 |
+
# logs = gr.Textbox()
|
58 |
+
# demo.load(read_logs, None, logs, every=1)
|
59 |
+
#
|
60 |
+
# demo.launch(enable_queue=True, show_error=True)
|
61 |
+
|
62 |
+
|
63 |
+
# with gr.Blocks() as demo:
|
64 |
+
# with gr.Row():
|
65 |
+
# inputs = gr.inputs.Audio(type="filepath")
|
66 |
+
# outputs = ["text", 'plot']
|
67 |
+
# btn = gr.Button("Run")
|
68 |
+
# btn.click(predict_uri, inputs, outputs)
|
69 |
+
#
|
70 |
+
# logs = gr.Textbox()
|
71 |
+
# demo.load(read_logs, None, logs, every=1)
|
72 |
+
#
|
73 |
+
# demo.queue().launch()
|
74 |
+
|
75 |
+
|
76 |
+
demo = gr.Interface(
|
77 |
+
predict_uri,
|
78 |
+
inputs=[
|
79 |
+
gr.inputs.Audio(type="filepath"),
|
80 |
+
gr.inputs.Audio(source="microphone", type="filepath"),
|
81 |
+
gr.Slider(minimum=7, maximum=21, step=1)
|
82 |
+
],
|
83 |
+
outputs=['image', 'image', 'image', 'text', 'text', 'text', 'text'],
|
84 |
+
# examples=examples,
|
85 |
+
title=title,
|
86 |
+
description=description,
|
87 |
+
allow_flagging='never'
|
88 |
+
)
|
89 |
+
demo.launch(enable_queue=True, show_error=True, share=False)
|
90 |
+
|
91 |
+
# # FastAPI
|
92 |
+
# CUSTOM_PATH = "/gradio"
|
93 |
+
#
|
94 |
+
# app = FastAPI()
|
95 |
+
#
|
96 |
+
#
|
97 |
+
# @app.get("/")
|
98 |
+
# def read_main():
|
99 |
+
# return {"message": "This is your main app"}
|
100 |
+
#
|
101 |
+
#
|
102 |
+
# io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
|
103 |
+
# app = gr.mount_gradio_app(app, io, path=CUSTOM_PATH)
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Pillow
|
2 |
+
librosa
|
3 |
+
soundfile
|
4 |
+
matplotlib==3.7.2
|
5 |
+
gradio
|
6 |
+
tensorflow
|
7 |
+
tensorflow_hub
|
8 |
+
numpy
|
9 |
+
scipy
|
10 |
+
pydub
|
11 |
+
seaborn
|