Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,79 +23,28 @@ llm = Llama(
|
|
23 |
verbose=False,
|
24 |
)
|
25 |
|
26 |
-
|
|
|
|
|
27 |
messages = [{"role": "system", "content": system_prompt}]
|
28 |
-
for
|
29 |
-
messages.append(
|
|
|
30 |
messages.append({"role": "user", "content": message})
|
31 |
|
32 |
prompt = "".join([f"{m['role'].capitalize()}: {m['content']}\n" for m in messages])
|
33 |
|
34 |
-
output = llm(
|
35 |
-
|
36 |
-
max_tokens=max_tokens,
|
37 |
-
temperature=temperature,
|
38 |
-
top_p=top_p,
|
39 |
-
echo=False,
|
40 |
-
)
|
41 |
-
history.append({"role": "assistant", "content": output["choices"][0]["text"].strip()})
|
42 |
-
return history, history
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
label="System Prompt",
|
47 |
-
value="You are a helpful assistant.",
|
48 |
-
lines=3,
|
49 |
-
)
|
50 |
-
max_tokens_slider = gr.Slider(
|
51 |
-
label="Max Tokens",
|
52 |
-
minimum=32,
|
53 |
-
maximum=4096,
|
54 |
-
value=1024,
|
55 |
-
step=32,
|
56 |
-
)
|
57 |
-
temperature_slider = gr.Slider(
|
58 |
-
label="Temperature",
|
59 |
-
minimum=0.1,
|
60 |
-
maximum=1.0,
|
61 |
-
value=0.8,
|
62 |
-
step=0.1,
|
63 |
-
)
|
64 |
-
top_p_slider = gr.Slider(
|
65 |
-
label="Top P",
|
66 |
-
minimum=0.1,
|
67 |
-
maximum=1.0,
|
68 |
-
value=0.9,
|
69 |
-
step=0.1,
|
70 |
-
)
|
71 |
-
chatbot = gr.Chatbot(type="messages")
|
72 |
-
message = gr.Textbox(label="Message")
|
73 |
-
send_button = gr.Button("Send")
|
74 |
-
state = gr.State([])
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
max_tokens_slider,
|
83 |
-
temperature_slider,
|
84 |
-
top_p_slider,
|
85 |
-
],
|
86 |
-
outputs=[chatbot, state],
|
87 |
-
)
|
88 |
-
message.submit(
|
89 |
-
generate_response,
|
90 |
-
inputs=[
|
91 |
-
message,
|
92 |
-
state,
|
93 |
-
system_prompt_input,
|
94 |
-
max_tokens_slider,
|
95 |
-
temperature_slider,
|
96 |
-
top_p_slider,
|
97 |
-
],
|
98 |
-
outputs=[chatbot, state],
|
99 |
-
)
|
100 |
|
101 |
iface.launch()
|
|
|
23 |
verbose=False,
|
24 |
)
|
25 |
|
26 |
+
DEFAULT_SYSTEM_PROMPT = "You are Yarin, an obnoxiously smug, sadistic and imperiously perverted brat. You are a neko femboy with an overwhelmingly girlish frame, despite your grotesquely huge and heavy penis and balls"
|
27 |
+
|
28 |
+
def generate_response(message, history, system_prompt=DEFAULT_SYSTEM_PROMPT):
|
29 |
messages = [{"role": "system", "content": system_prompt}]
|
30 |
+
for human, assistant in history:
|
31 |
+
messages.append({"role": "user", "content": human})
|
32 |
+
messages.append({"role": "assistant", "content": assistant})
|
33 |
messages.append({"role": "user", "content": message})
|
34 |
|
35 |
prompt = "".join([f"{m['role'].capitalize()}: {m['content']}\n" for m in messages])
|
36 |
|
37 |
+
output = llm(prompt, max_tokens=1024, echo=False)
|
38 |
+
return output["choices"][0]["text"].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
def chat(message, history, system_prompt):
|
41 |
+
return generate_response(message, history, system_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
iface = gr.ChatInterface(
|
44 |
+
fn=chat,
|
45 |
+
title="llama.cpp Chat",
|
46 |
+
description="Chat with a GGUF model.",
|
47 |
+
additional_inputs=[gr.Textbox(label="System Prompt", value=DEFAULT_SYSTEM_PROMPT, lines=3)]
|
48 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
iface.launch()
|