Update app.py
Browse files
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 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
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 |
-
|
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 |
"""
|