Spaces:
Sleeping
Sleeping
Commit
•
5fd8e54
1
Parent(s):
d1ada29
Update app.py
Browse files
app.py
CHANGED
@@ -13,15 +13,14 @@ pipeline = PIPELINE(model, "rwkv_vocab_v20230424")
|
|
13 |
|
14 |
|
15 |
def generate_prompt(instruction, input=None, history=None):
|
16 |
-
# parse the chat history into a string of user and assistant messages
|
17 |
-
history_str = ""
|
18 |
-
|
19 |
has_history = (history is not None)
|
20 |
if has_history:
|
|
|
21 |
for pair in history:
|
22 |
if len(pair[0]) > 0 and len(pair[1]) > 0:
|
23 |
-
|
24 |
-
|
|
|
25 |
if instruction:
|
26 |
instruction = (
|
27 |
instruction.strip()
|
@@ -29,21 +28,20 @@ def generate_prompt(instruction, input=None, history=None):
|
|
29 |
.replace("\n\n", "\n")
|
30 |
.replace("\n\n", "\n")
|
31 |
)
|
32 |
-
if input:
|
33 |
input = (
|
34 |
input.strip()
|
35 |
.replace("\r\n", "\n")
|
36 |
.replace("\n\n", "\n")
|
37 |
.replace("\n\n", "\n")
|
38 |
)
|
39 |
-
|
40 |
-
return f"""{history_str}Instruction: {instruction}
|
41 |
|
42 |
Input: {input}
|
43 |
|
44 |
Response:"""
|
45 |
else:
|
46 |
-
return f"""
|
47 |
|
48 |
Assistant:"""
|
49 |
|
@@ -177,7 +175,11 @@ def alternative(chatbot, history):
|
|
177 |
|
178 |
with gr.Blocks(title=title) as demo:
|
179 |
gr.HTML(f'<div style="text-align: center;">\n<h1>🌍World - {title}</h1>\n</div>')
|
180 |
-
|
|
|
|
|
|
|
|
|
181 |
with gr.Tab("Chat mode"):
|
182 |
with gr.Row():
|
183 |
with gr.Column():
|
@@ -243,9 +245,6 @@ with gr.Blocks(title=title) as demo:
|
|
243 |
)
|
244 |
|
245 |
with gr.Tab("Instruct mode"):
|
246 |
-
gr.Markdown(
|
247 |
-
f"100% RNN RWKV-LM **trained on 100+ natural languages**. Demo limited to ctxlen {ctx_limit}. For best results, <b>keep your prompt short and clear</b>."
|
248 |
-
)
|
249 |
with gr.Row():
|
250 |
with gr.Column():
|
251 |
instruction = gr.Textbox(
|
|
|
13 |
|
14 |
|
15 |
def generate_prompt(instruction, input=None, history=None):
|
|
|
|
|
|
|
16 |
has_history = (history is not None)
|
17 |
if has_history:
|
18 |
+
input = "\""
|
19 |
for pair in history:
|
20 |
if len(pair[0]) > 0 and len(pair[1]) > 0:
|
21 |
+
input += f"User: {pair[0]}\nAssistant: {pair[1]}\n"
|
22 |
+
input = input[:-1] + "\"\n" + f"User: {instruction}"
|
23 |
+
instruction = "Based on the Conversation History, generate a Response for the User."
|
24 |
if instruction:
|
25 |
instruction = (
|
26 |
instruction.strip()
|
|
|
28 |
.replace("\n\n", "\n")
|
29 |
.replace("\n\n", "\n")
|
30 |
)
|
31 |
+
if input and len(input) > 0:
|
32 |
input = (
|
33 |
input.strip()
|
34 |
.replace("\r\n", "\n")
|
35 |
.replace("\n\n", "\n")
|
36 |
.replace("\n\n", "\n")
|
37 |
)
|
38 |
+
return f"""Instruction: {instruction}
|
|
|
39 |
|
40 |
Input: {input}
|
41 |
|
42 |
Response:"""
|
43 |
else:
|
44 |
+
return f"""User: {instruction}
|
45 |
|
46 |
Assistant:"""
|
47 |
|
|
|
175 |
|
176 |
with gr.Blocks(title=title) as demo:
|
177 |
gr.HTML(f'<div style="text-align: center;">\n<h1>🌍World - {title}</h1>\n</div>')
|
178 |
+
gr.Markdown(
|
179 |
+
f"100% RNN RWKV-LM **trained on 100+ natural languages**. Demo limited to ctxlen {ctx_limit}. For best results, <b>keep your prompt short and clear</b>."
|
180 |
+
+ "\n\n"
|
181 |
+
+ f"Clone this space for faster inference if you can run the app on GPU or better CPU. To use CUDA, replace <code>strategy='cpu bf16'</code> with <code>strategy='cuda fp16'</code> in `app.py`."
|
182 |
+
)
|
183 |
with gr.Tab("Chat mode"):
|
184 |
with gr.Row():
|
185 |
with gr.Column():
|
|
|
245 |
)
|
246 |
|
247 |
with gr.Tab("Instruct mode"):
|
|
|
|
|
|
|
248 |
with gr.Row():
|
249 |
with gr.Column():
|
250 |
instruction = gr.Textbox(
|