YC-Chen commited on
Commit
f93772b
1 Parent(s): a916d48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import requests
3
  import json
 
4
 
5
  import gradio as gr
6
  from transformers import AutoTokenizer
@@ -44,6 +45,8 @@ HEADERS = {
44
  PRESENCE_PENALTY=0
45
  FREQUENCY_PENALTY=1.1
46
 
 
 
47
  tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breeze-7B-Instruct-v0_1")
48
 
49
  def refusal_condition(query):
@@ -153,7 +156,8 @@ with gr.Blocks() as demo:
153
  "frequency_penalty": FREQUENCY_PENALTY,
154
  "stream": True,
155
  }
156
-
 
157
  with requests.post(API_URL, headers=HEADERS, data=json.dumps(data), stream=True) as r:
158
  for response in r.iter_lines():
159
  if len(response) > 0:
@@ -169,6 +173,8 @@ with gr.Blocks() as demo:
169
  history[-1][1] += delta
170
 
171
  yield history
 
 
172
 
173
  if history[-1][1].endswith('</s>'):
174
  history[-1][1] = history[-1][1][:-4]
@@ -262,5 +268,5 @@ with gr.Blocks() as demo:
262
 
263
  gr.Markdown(LICENSE)
264
 
265
- demo.queue(concurrency_count=1, max_size=32)
266
  demo.launch()
 
1
  import os
2
  import requests
3
  import json
4
+ import time
5
 
6
  import gradio as gr
7
  from transformers import AutoTokenizer
 
45
  PRESENCE_PENALTY=0
46
  FREQUENCY_PENALTY=1.1
47
 
48
+ MAX_SEC = 30
49
+
50
  tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breeze-7B-Instruct-v0_1")
51
 
52
  def refusal_condition(query):
 
156
  "frequency_penalty": FREQUENCY_PENALTY,
157
  "stream": True,
158
  }
159
+
160
+ start_time = time.time()
161
  with requests.post(API_URL, headers=HEADERS, data=json.dumps(data), stream=True) as r:
162
  for response in r.iter_lines():
163
  if len(response) > 0:
 
173
  history[-1][1] += delta
174
 
175
  yield history
176
+ if time.time() - start_time > MAX_SEC:
177
+ break
178
 
179
  if history[-1][1].endswith('</s>'):
180
  history[-1][1] = history[-1][1][:-4]
 
268
 
269
  gr.Markdown(LICENSE)
270
 
271
+ demo.queue(concurrency_count=1, max_size=128)
272
  demo.launch()