YingxuHe commited on
Commit
d1ebb9a
·
verified ·
1 Parent(s): 6a8f361

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +18 -3
utils.py CHANGED
@@ -1,5 +1,6 @@
1
- import os
2
  import io
 
 
3
 
4
  import librosa
5
  import paramiko
@@ -10,6 +11,10 @@ from sshtunnel import SSHTunnelForwarder
10
  local_port = int(os.getenv('LOCAL_PORT'))
11
 
12
 
 
 
 
 
13
  @st.cache_resource()
14
  def start_server():
15
  pkey = paramiko.RSAKey.from_private_key(io.StringIO(os.getenv('PRIVATE_KEY')))
@@ -41,7 +46,17 @@ def load_model():
41
  return client, model_name
42
 
43
 
44
- def generate_response(text_input):
 
 
 
 
 
 
 
 
 
 
45
  stream = st.session_state.client.chat.completions.create(
46
  messages=[{
47
  "role":
@@ -66,7 +81,7 @@ def generate_response(text_input):
66
  stream=True,
67
  )
68
 
69
- return stream
70
 
71
 
72
  def bytes_to_array(audio_bytes):
 
 
1
  import io
2
+ import os
3
+ import re
4
 
5
  import librosa
6
  import paramiko
 
11
  local_port = int(os.getenv('LOCAL_PORT'))
12
 
13
 
14
+ class NoAudioException(Exception):
15
+ pass
16
+
17
+
18
  @st.cache_resource()
19
  def start_server():
20
  pkey = paramiko.RSAKey.from_private_key(io.StringIO(os.getenv('PRIVATE_KEY')))
 
46
  return client, model_name
47
 
48
 
49
+ def generate_response(text_input):
50
+ if not st.session_state.audio_base64:
51
+ raise NoAudioException("audio is empty.")
52
+
53
+ warnings = []
54
+ if re.search("tool|code|python|java|math|calculate", text_input):
55
+ warnings.append("WARNING: MERaLiON-AudioLLM is not intended for use in tool calling, math, and coding tasks.")
56
+
57
+ if re.search(r'[\u4e00-\u9fff]+', text_input):
58
+ warnings.append("NOTE: Please try to prompt in English for the best performance.")
59
+
60
  stream = st.session_state.client.chat.completions.create(
61
  messages=[{
62
  "role":
 
81
  stream=True,
82
  )
83
 
84
+ return stream, warnings
85
 
86
 
87
  def bytes_to_array(audio_bytes):