Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,17 @@
|
|
| 1 |
from warnings import filterwarnings
|
| 2 |
filterwarnings("ignore")
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
-
import pyaudio
|
| 6 |
-
import wave
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"audio-classification", model="MIT/ast-finetuned-speech-commands-v2", device=device
|
| 11 |
-
)
|
| 12 |
|
| 13 |
-
def
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
frames.append(data)
|
| 20 |
-
stream.stop_stream()
|
| 21 |
-
stream.close()
|
| 22 |
-
audio.terminate()
|
| 23 |
-
return b''.join(frames)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
chunk_length_s=2.0,
|
| 29 |
-
stream_chunk_s=0.25,
|
| 30 |
-
debug=False,
|
| 31 |
-
):
|
| 32 |
-
if wake_word not in classifier.model.config.label2id.keys():
|
| 33 |
-
raise ValueError(
|
| 34 |
-
f"Wake word {wake_word} not in set of valid class labels, pick a wake word in the set {classifier.model.config.label2id.keys()}."
|
| 35 |
-
)
|
| 36 |
-
audio_data = record_audio(chunk_length_s, stream_chunk_s)
|
| 37 |
-
prediction = classifier(audio_data)
|
| 38 |
-
prediction = prediction[0]
|
| 39 |
-
if debug:
|
| 40 |
-
print(prediction)
|
| 41 |
-
if prediction["label"] == wake_word:
|
| 42 |
-
if prediction["score"] > prob_threshold:
|
| 43 |
-
return True
|
| 44 |
-
return False
|
| 45 |
-
|
| 46 |
-
if __name__ == "__main__":
|
| 47 |
-
launch_fn(debug=True)
|
|
|
|
| 1 |
from warnings import filterwarnings
|
| 2 |
filterwarnings("ignore")
|
| 3 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def function2(x):
|
| 6 |
+
print("Triggered 2")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def function1(x):
|
| 9 |
+
if x == "1": # Convert x to a string for comparison
|
| 10 |
+
print("Triggered 1")
|
| 11 |
+
with gr.Blocks():
|
| 12 |
+
demo1 = gr.Interface(fn=function2, inputs=gr.Textbox(label="Input for Function 2"), outputs=[], title="Function 2 Interface")
|
| 13 |
+
demo1.launch(share=True, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
with gr.Blocks():
|
| 16 |
+
demo = gr.Interface(fn=function1, inputs=gr.Textbox(label="Input for Function 1"), outputs=[], title="Function 1 Interface")
|
| 17 |
+
demo.launch(share=True, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|