schuler commited on
Commit
f076786
·
verified ·
1 Parent(s): 2b0b840

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -26
app.py CHANGED
@@ -18,14 +18,15 @@ def load_model(repo_name):
18
  # model.to('cuda')
19
  return tokenizer, generator_conf, model
20
 
21
- tokenizer, generator_conf, model, generator = False, False, False, False
22
- with gr.Blocks() as main_block:
23
- tokenizer, generator_conf, model = load_model(REPO_NAME)
24
- global_error = ''
25
- try:
26
- generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
27
- except Exception as e:
28
- global_error = f"Failed to load model: {str(e)}"
 
29
 
30
  @spaces.GPU()
31
  def respond(
@@ -54,8 +55,7 @@ def respond(
54
  for hmessage in messages:
55
  role = "<|assistant|>" if hmessage['role'] == 'assistant' else "<|user|>"
56
  prompt += f"{role}{hmessage['content']}<|end|>"
57
- # prompt += f"<|user|>{message}<|end|><|assistant|>"
58
- prompt += f"<|assistant|>"
59
 
60
  # """
61
  # Generate the response
@@ -82,22 +82,6 @@ def respond(
82
 
83
  yield result
84
 
85
-
86
- """
87
- for message in client.chat_completion(
88
- messages,
89
- max_tokens=max_tokens,
90
- stream=True,
91
- temperature=temperature,
92
- top_p=top_p,
93
- ):
94
- token = message.choices[0].delta.content
95
-
96
- response += token
97
- yield response
98
- """
99
-
100
-
101
  """
102
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
103
  """
 
18
  # model.to('cuda')
19
  return tokenizer, generator_conf, model
20
 
21
+ # tokenizer, generator_conf, model, generator = False, False, False, False
22
+ # with gr.Blocks() as main_block:
23
+
24
+ tokenizer, generator_conf, model = load_model(REPO_NAME)
25
+ global_error = ''
26
+ try:
27
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
28
+ except Exception as e:
29
+ global_error = f"Failed to load model: {str(e)}"
30
 
31
  @spaces.GPU()
32
  def respond(
 
55
  for hmessage in messages:
56
  role = "<|assistant|>" if hmessage['role'] == 'assistant' else "<|user|>"
57
  prompt += f"{role}{hmessage['content']}<|end|>"
58
+ prompt += f"<|assistant|>\n"
 
59
 
60
  # """
61
  # Generate the response
 
82
 
83
  yield result
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  """
86
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
87
  """