KrishGoyani commited on
Commit
44733a3
·
verified ·
1 Parent(s): 50c2d10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -42
app.py CHANGED
@@ -1,47 +1,17 @@
1
  from warnings import filterwarnings
2
  filterwarnings("ignore")
3
- from transformers import pipeline
4
- import torch
5
- import pyaudio
6
- import wave
7
 
8
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
9
- classifier = pipeline(
10
- "audio-classification", model="MIT/ast-finetuned-speech-commands-v2", device=device
11
- )
12
 
13
- def record_audio(chunk_length_s=2.0, stream_chunk_s=0.25):
14
- audio = pyaudio.PyAudio()
15
- stream = audio.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=int(16000 * stream_chunk_s))
16
- frames = []
17
- for _ in range(int(chunk_length_s / stream_chunk_s)):
18
- data = stream.read(int(16000 * stream_chunk_s))
19
- frames.append(data)
20
- stream.stop_stream()
21
- stream.close()
22
- audio.terminate()
23
- return b''.join(frames)
24
 
25
- def launch_fn(
26
- wake_word="marvin",
27
- prob_threshold=0.5,
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)