nsajadi commited on
Commit
9b76c42
·
1 Parent(s): 71492f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -49
app.py CHANGED
@@ -1,54 +1,56 @@
1
- #from transformers import pipeline
2
- #import streamlit as st
3
-
4
- #pipe = pipeline('sentiment-analysis')
5
- #text = st.text_area('Enter some text here!')
6
-
7
- #if text:
8
- # out = pipe(text)
9
- # st.json(out)
10
-
11
-
12
  from transformers import pipeline
 
13
  import torch
14
 
15
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
16
- classifier = pipeline(
17
- "audio-classification", model="MIT/ast-finetuned-speech-commands-v2", device=device
18
- )
19
-
20
- from transformers.pipelines.audio_utils import ffmpeg_microphone_live
21
-
22
-
23
- def launch_fn(
24
- wake_word="marvin",
25
- prob_threshold=0.5,
26
- chunk_length_s=2.0,
27
- stream_chunk_s=1,
28
- debug=False,
29
- ):
30
- if wake_word not in classifier.model.config.label2id.keys():
31
- raise ValueError(
32
- f"Wake word {wake_word} not in set of valid class labels, pick a wake word in the set {classifier.model.config.label2id.keys()}."
33
- )
34
-
35
- sampling_rate = classifier.feature_extractor.sampling_rate
36
-
37
- mic = ffmpeg_microphone_live(
38
- sampling_rate=sampling_rate,
39
- chunk_length_s=chunk_length_s,
40
- stream_chunk_s=stream_chunk_s,
41
- )
42
-
43
- print("Listening for wake word...")
44
- mic_results = classifier(mic)
45
- for prediction in mic_results:
46
- prediction = prediction[0]
47
- if debug:
48
- print(prediction)
49
- if prediction["label"] == wake_word:
50
- if prediction["score"] > prob_threshold:
51
- return True
52
-
53
- launch_fn(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
+ import streamlit as st
3
  import torch
4
 
5
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
6
+ pipe = pipeline('chat-response', 'liuhaotian/llava-v1.5-13b', device=device )
7
+ text = st.text_area('Enter some text here!')
8
+
9
+ if text:
10
+ out = pipe(text)
11
+ st.json(out)
12
+
13
+
14
+ # from transformers import pipeline
15
+ # import torch
16
+
17
+ # device = "cuda:0" if torch.cuda.is_available() else "cpu"
18
+ # classifier = pipeline(
19
+ # "audio-classification", model="MIT/ast-finetuned-speech-commands-v2", device=device
20
+ # )
21
+
22
+ # from transformers.pipelines.audio_utils import ffmpeg_microphone_live
23
+
24
+
25
+ # def launch_fn(
26
+ # wake_word="marvin",
27
+ # prob_threshold=0.5,
28
+ # chunk_length_s=2.0,
29
+ # stream_chunk_s=1,
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
+
37
+ # sampling_rate = classifier.feature_extractor.sampling_rate
38
+
39
+ # mic = ffmpeg_microphone_live(
40
+ # sampling_rate=sampling_rate,
41
+ # chunk_length_s=chunk_length_s,
42
+ # stream_chunk_s=stream_chunk_s,
43
+ # )
44
+
45
+ # print("Listening for wake word...")
46
+ # mic_results = classifier(mic)
47
+ # for prediction in mic_results:
48
+ # prediction = prediction[0]
49
+ # if debug:
50
+ # print(prediction)
51
+ # if prediction["label"] == wake_word:
52
+ # if prediction["score"] > prob_threshold:
53
+ # return True
54
+
55
+ # launch_fn(debug=True)
56