hanAlex commited on
Commit
f31d0c8
Β·
verified Β·
1 Parent(s): b363e26

Update web_demo.py

Browse files
Files changed (1) hide show
  1. web_demo.py +20 -11
web_demo.py CHANGED
@@ -114,18 +114,27 @@ if __name__ == "__main__":
114
  if "<|system|>" not in inputs:
115
  inputs += f"<|system|>\n{system_prompt}"
116
  inputs += f"<|user|>\n{user_input}<|assistant|>streaming_transcription\n"
117
-
 
118
  with torch.no_grad():
119
- response = requests.post(
120
- "http://localhost:10000/generate_stream",
121
- data=json.dumps({
122
- "prompt": inputs,
123
- "temperature": temperature,
124
- "top_p": top_p,
125
- "max_new_tokens": max_new_token,
126
- }),
127
- stream=True
128
- )
 
 
 
 
 
 
 
 
129
  text_tokens, audio_tokens = [], []
130
  audio_offset = glm_tokenizer.convert_tokens_to_ids('<|audio_0|>')
131
  end_token_id = glm_tokenizer.convert_tokens_to_ids('<|user|>')
 
114
  if "<|system|>" not in inputs:
115
  inputs += f"<|system|>\n{system_prompt}"
116
  inputs += f"<|user|>\n{user_input}<|assistant|>streaming_transcription\n"
117
+
118
+ global use_local_interface , worker
119
  with torch.no_grad():
120
+ if use_local_interface :
121
+ params = { "prompt": inputs,
122
+ "temperature": temperature,
123
+ "top_p": top_p,
124
+ "max_new_tokens": max_new_token, }
125
+ response = worker.generate_stream( params )
126
+
127
+ else :
128
+ response = requests.post(
129
+ "http://localhost:10000/generate_stream",
130
+ data=json.dumps({
131
+ "prompt": inputs,
132
+ "temperature": temperature,
133
+ "top_p": top_p,
134
+ "max_new_tokens": max_new_token,
135
+ }),
136
+ stream=True
137
+ )
138
  text_tokens, audio_tokens = [], []
139
  audio_offset = glm_tokenizer.convert_tokens_to_ids('<|audio_0|>')
140
  end_token_id = glm_tokenizer.convert_tokens_to_ids('<|user|>')